Skip to content

Commit

Permalink
Merge pull request #37 from SharePoint/dev
Browse files Browse the repository at this point in the history
Prepare v1.4.2 release
  • Loading branch information
estruyf authored Mar 15, 2018
2 parents c053ca2 + 4e6bfee commit f046a2f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Releases

## 1.4.2

**Enhancements**

- Introduced the `onGetErrorMessage` property for the `PropertyFieldNumber` field control ([#36 - PropertyFieldNumber control suggestion](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/36))

## 1.4.1

**Enhancements**

- Optimized telemetry so that it only pushes control data

**Fixes**

- Fixes for issue [#30 - Check if Label is null and if so don't render it.](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/30)
- Fix for issue [#33 - `PropertyFieldPeoplePicker` Validation does not work as expected.](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/33)

Expand Down
7 changes: 7 additions & 0 deletions docs/documentation/docs/about/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Releases

## 1.4.2

**Enhancements**

- Introduced the `onGetErrorMessage` property for the `PropertyFieldNumber` field control ([#36 - PropertyFieldNumber control suggestion](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/36))

## 1.4.1

**Enhancements**

- Optimized telemetry so that it only pushes control data

**Fixes**

- Fixes for issue [#30 - Check if Label is null and if so don't render it.](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/30)
- Fix for issue [#33 - `PropertyFieldPeoplePicker` Validation does not work as expected.](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/33)

Expand Down
21 changes: 21 additions & 0 deletions docs/documentation/docs/controls/PropertyFieldNumber.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ PropertyFieldNumber("numberValue", {
})
```

You can also implement your own validation with the `onGetErrorMessage` property as follows:

```TypeScript
PropertyFieldNumber("numberValue", {
key: "numberValue",
label: "Number value only",
description: "Number field description",
value: this.properties.numberValue,
maxValue: 10,
minValue: 1,
disabled: false,
onGetErrorMessage: (value: number) => {
if (value % 2 !== 0) {
return 'Only even numbers are allowed';
}
return '';
}
})
```

## Implementation

The `PropertyFieldNumber` control can be configured with the following properties:
Expand All @@ -52,6 +72,7 @@ The `PropertyFieldNumber` control can be configured with the following propertie
| minValue | number | no | Minimum number that can be inserted. |
| disabled | boolean | no | Specify if the control needs to be disabled. |
| errorMessage | string | no | If set, this will be displayed as an error message. |
| onGetErrorMessage | (value: number) => string | no | If set, this method is used to get the validation error message and determine whether the input value is valid or not. |
| deferredValidationTime | number | no | Number field will start to validate after users stop typing for `deferredValidationTime` milliseconds. |


Expand Down
3 changes: 2 additions & 1 deletion docs/documentation/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install @pnp/spfx-property-controls --save --save-exact
Once the package is installed, you will have to configure the resource file of the property controls to be used in your project. You can do this by opening the `config/config.json` and adding the following line to the `localizedResources` property:

```json
"PropertyControlStrings": "./node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
```

## Controls
Expand All @@ -35,6 +35,7 @@ The following controls are currently available:
- [PropertyFieldSpinButton](./controls/PropertyFieldSpinButton) (Property pane spin button)
- [PropertyFieldTermPicker](./controls/PropertyFieldTermPicker) (Property pane managed metadata term selector)
- [PropertyFieldMultiSelect](./controls/PropertyFieldMultiSelect) (Property pane field which allows multi-value selection)
- [PropertyFieldNumber](./controls/PropertyFieldNumber) (Property pane field which allows only number values)

The following controls are extended controls that show a callout next to the label

Expand Down
1 change: 1 addition & 0 deletions docs/documentation/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pages:
- PropertyFieldSpinButton: 'controls/PropertyFieldSpinButton.md'
- PropertyFieldTermPicker: 'controls/PropertyFieldTermPicker.md'
- PropertyFieldMultiSelect: 'controls/PropertyFieldMultiSelect.md'
- PropertyFieldNumber: 'controls/PropertyFieldNumber.md'
- 'Controls with callout':
- PropertyFieldButtonWithCallout: 'controls/PropertyFieldButtonWithCallout.md'
- PropertyFieldCheckboxWithCallout: 'controls/PropertyFieldCheckboxWithCallout.md'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@pnp/spfx-property-controls",
"description": "Reusable property pane controls for SharePoint Framework solutions",
"version": "1.4.1",
"version": "1.4.2",
"engines": {
"node": ">=0.10.0"
},
Expand Down
13 changes: 13 additions & 0 deletions src/propertyFields/number/IPropertyFieldNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ export interface IPropertyFieldNumberProps {
* So, make sure to set this only if you want to see an error message dispalyed for the text field.
*/
errorMessage?: string;
/**
* The method is used to get the validation error message and determine whether the input value is valid or not.
*
* When it returns string:
* - If valid, it returns empty string.
* - If invalid, it returns the error message string and an error message is displayed below the text field.
*
* When it returns Promise<string>:
* - The resolved value is display as error message.
* - The rejected, the value is thrown away.
*
*/
onGetErrorMessage?: (value: number) => string | Promise<string>;
/**
* Number field will start to validate after users stop typing for `deferredValidationTime` milliseconds.
* Default value is 200.
Expand Down
8 changes: 6 additions & 2 deletions src/propertyFields/number/PropertyFieldNumberHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class PropertyFieldNumberHost extends React.Component<IPropertyFi
* Validate if field value is a number
* @param value
*/
private _validateNumber = (value: string): string => {
private _validateNumber = (value: string): string | Promise<string> => {
if (isNaN(Number(value))) {
return `${strings.NotNumberValidationMessage} ${value}.`;
}
Expand All @@ -43,7 +43,11 @@ export default class PropertyFieldNumberHost extends React.Component<IPropertyFi
return `${strings.MaximumNumberValidationMessage} ${this.props.maxValue}`;
}

return '';
if (this.props.onGetErrorMessage) {
return this.props.onGetErrorMessage(nrValue);
} else {
return '';
}
}

/**
Expand Down

0 comments on commit f046a2f

Please sign in to comment.