|
| 1 | +# PropertyFieldNumber control |
| 2 | + |
| 3 | +This control generates an input field for numbers. Text is not allowed as this will result into an invalid input. |
| 4 | + |
| 5 | +**PropertyFieldNumber example usage** |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## How to use this control in your solutions |
| 10 | + |
| 11 | +1. Check that you installed the `@pnp/spfx-property-controls` dependency. Check out The [getting started](../#getting-started) page for more information about installing the dependency. |
| 12 | +2. Import the following modules to your component: |
| 13 | + |
| 14 | +```TypeScript |
| 15 | +import { PropertyFieldNumber } from '@pnp/spfx-property-controls/lib/PropertyFieldNumber'; |
| 16 | +``` |
| 17 | + |
| 18 | +3. Create a new property for your web part, for example: |
| 19 | + |
| 20 | +```TypeScript |
| 21 | +export interface IPropertyControlsTestWebPartProps { |
| 22 | + numberValue: number; |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +4. Add the custom property control to the `groupFields` of the web part property pane configuration: |
| 27 | + |
| 28 | +```TypeScript |
| 29 | +PropertyFieldNumber("numberValue", { |
| 30 | + key: "numberValue", |
| 31 | + label: "Number value only", |
| 32 | + description: "Number field description", |
| 33 | + value: this.properties.numberValue, |
| 34 | + maxValue: 10, |
| 35 | + minValue: 1, |
| 36 | + disabled: false |
| 37 | +}) |
| 38 | +``` |
| 39 | + |
| 40 | +## Implementation |
| 41 | + |
| 42 | +The `PropertyFieldNumber` control can be configured with the following properties: |
| 43 | + |
| 44 | +| Property | Type | Required | Description | |
| 45 | +| ---- | ---- | ---- | ---- | |
| 46 | +| key | string | yes | An unique key that indicates the identity of this control. | |
| 47 | +| label | string | yes | Property field label displayed on top. | |
| 48 | +| description | string | no | The number field input description. | |
| 49 | +| placeholder | string | no | Placeholder text to be displayed in the number field. | |
| 50 | +| value | number | no | Value to be displayed in the number field. | |
| 51 | +| maxValue | number | no | Maximum number that can be inserted. | |
| 52 | +| minValue | number | no | Minimum number that can be inserted. | |
| 53 | +| disabled | boolean | no | Specify if the control needs to be disabled. | |
| 54 | +| errorMessage | string | no | If set, this will be displayed as an error message. | |
| 55 | +| deferredValidationTime | number | no | Number field will start to validate after users stop typing for `deferredValidationTime` milliseconds. | |
| 56 | + |
| 57 | + |
| 58 | + |
0 commit comments