@maif/react-forms 1.0.2 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- name: Release Daikoku
1
+ name: Release react-forms
2
2
  on:
3
3
  push:
4
4
  tags:
package/README.md CHANGED
@@ -65,7 +65,6 @@ export const Example = () => {
65
65
 
66
66
  - **type** (required): the type of value. It provided by the imported object `type`. It could be just string like `string`, `number`, `bool`, `object`, `date` or `file`
67
67
  - **format**: Over the type you can display a special format for the field. It provided by the imported object `format` or just a string
68
- - `array`: if the value is an array of basic type, display multiple fields with "add" and "remove" buttons
69
68
  - `select`: display a [react-select](https://react-select.com/home) field with provided options
70
69
  - `code`: if the type is `string`, display a code input (draw with [react-ace](https://github.com/securingsincity/react-ace))
71
70
  - `markdown`: if the type is `string`, display a markdown input
@@ -74,13 +73,21 @@ export const Example = () => {
74
73
  - `password`: if the type is `string`, display a password input
75
74
  - `hidden`: if the type is `string`, add an hidden input in your form
76
75
  - `form`: if the type is `object`, display a form in your form draw with given schema and flow.
76
+ - **array**: boolean value to display multiple fields with "add" and "remove" buttons (`false` by default)
77
+ - **createOption**: if `select` format is choosen, `createOption` property is to render a Creatable component
78
+ - **onCreateOption**: if `select` format is choosen, `onCreateOption` property is a function called before new option creation
79
+ ```javascript
80
+ {
81
+ onCreateOption: (option) => myFunction(option)
82
+ }
83
+ ```
77
84
  - **isMulti**: if `select` format is choosen, `isMulti` property is to render a multiselect component
78
85
  - **defaultKeyValue**: if the format is setup to object, this default key/value is set for all added entries
79
86
  - **visible**: a boolean option to hide/display form field. It can be an object with `ref` property to get a value by reference an a key `test` as a function to test it. if there is no `test` key, it's base just on boolean value of the reference.
80
87
  - **disabled**: A boolean option to enable/disable form field
81
88
  - **label**: The label of form field
82
89
  - **placeholder**: the placeholder of form field
83
- - **defaultValue**: A default value to fill field y default
90
+ - **defaultValue**: A default value to fill field by default
84
91
  - **help**: the text display hover a help button
85
92
  - **className**: you can customize classnames of field,
86
93
  - **style**: to styling a field, you can provide a json object with css
@@ -88,7 +95,7 @@ export const Example = () => {
88
95
  ```javascript
89
96
  ({rawValues, value, onChange, error}) => <input type="text" className="is-invalid" value={value} onChange={e => onChange(e.target.value)} />
90
97
  ```
91
- - **props**: a json object merged with default props
98
+ - **props**: a json object merged with default props. For exemple, if format `select` is setup, you can add all [props](https://react-select.com/props) to csutomize react-select
92
99
  - **options**: An array of options for the select field (if format `select` is setup)
93
100
  - **optionsFrom**: A url to fetch array of options for the select field (if format `select` is setup)
94
101
  - **transformer**: A function to transform options to a valid format for react select, by default the code try to do it himself.
@@ -198,6 +205,7 @@ Possible constraints are provided by import `constraints` from **@maif/react-for
198
205
 
199
206
  - [mixed](#mixed)
200
207
  - [`constraints.required(message?:string)`](#constraintsrequiredmessagestring)
208
+ - [`constraints.nullable()`](#constraintsnullable)
201
209
  - [`constraints.test(name: string, message?:string, test: (val: any) => boolean | Promise<boolean>)`](#constraintstestname-string-messagestring-test-val-any--boolean--promiseboolean)
202
210
  - [`constraints.when(ref: string, test: (val: any) => boolean, then: any = [], otherwise: any = [])`](#constraintswhenref-string-test-val-any--boolean-then-any---otherwise-any--)
203
211
  - [`constraints.oneOf(arrayOfValues: any[], message?:string)`](#constraintsoneofarrayofvalues-any-messagestring)
@@ -222,6 +230,16 @@ the following methods works for all type types of value.
222
230
  {type: 'required', message: "this field is required"}
223
231
  ```
224
232
 
233
+ #### `constraints.nullable()`
234
+ Indicates the `null` is a valid value for the schema. Without `nullable` `null` will be treated as an error.
235
+
236
+ ```javascript
237
+ constraints.nullable()
238
+ ```
239
+ ```javascript
240
+ {type: 'nullable'}
241
+ ```
242
+
225
243
  #### `constraints.test(name: string, message?:string, test: (val: any) => boolean | Promise<boolean>)`
226
244
  Adds a test function to the validation chain. The test must provide a `name`, an error `message` and a validation function that takes in entry the current value and must return a boolean result. The test can return a promise that resolve a boolean result
227
245