react-jsonschema-form-extras 0.9.67 → 0.9.69
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.
- package/README.md +785 -785
- package/dist/form-with-extras.js +8 -8
- package/dist/form-with-extras.js.map +1 -1
- package/lib/CollapsibleField.js +152 -56
- package/lib/CollapsibleField.js.orig +402 -0
- package/lib/DraftRte.js +32 -32
- package/lib/TypeaheadField.js +8 -8
- package/lib/css/form-extras.css +10 -0
- package/lib/table/index.js +27 -44
- package/lib/table/tableConfFactory.js +18 -2
- package/lib/utils.js +14 -0
- package/package.json +138 -136
package/README.md
CHANGED
@@ -1,785 +1,785 @@
|
|
1
|
-
[](https://travis-ci.org/RxNT/react-jsonschema-form-extras)
|
2
|
-
[](https://coveralls.io/github/RxNT/react-jsonschema-form-extras)
|
3
|
-
[](https://badge.fury.io/js/react-jsonschema-form-extras)
|
4
|
-
|
5
|
-
|
6
|
-
# Catalogue
|
7
|
-
|
8
|
-
This project provides light integration over established React components,
|
9
|
-
trying to keep configurations compatible with original project.
|
10
|
-
All configurations you can specify in original projects, can be reused here.
|
11
|
-
|
12
|
-
- Composite array field (`ui:field` > `compositeArray`)
|
13
|
-
- Collapsible fields (`ui:field` > `collapsible`)
|
14
|
-
- Alternative input fields (`ui:field` > `altInput`)
|
15
|
-
- Typeahead, based on [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead) (`ui:field` > `typeahead`)
|
16
|
-
- Async Typeahead based on [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead) (`ui:field` > `asyncTypeahead`)
|
17
|
-
- RTE, based on [react-rte](https://github.com/sstur/react-rte) (`ui:field` > `rte`)
|
18
|
-
- Tables, based on [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table) (`ui:field` > `table`)
|
19
|
-
|
20
|
-
## Table of Contents
|
21
|
-
|
22
|
-
- [Use](#use)
|
23
|
-
- [Composite array field (compositeArray)](#composite-array-field-compositearray)
|
24
|
-
- [Purpose](#purpose)
|
25
|
-
- [Use](#use)
|
26
|
-
- [Properties](#properties)
|
27
|
-
- [Collapsible fields (collapsible)](#collapsible-fields-collapsible)
|
28
|
-
- [Purpose](#purpose)
|
29
|
-
- [Use](#use)
|
30
|
-
- [Properties](#properties)
|
31
|
-
- [Examples](#examples)
|
32
|
-
- [Using specific legend in collapsible field.](#using-specific-legend-in-collapsible-field)
|
33
|
-
- [Properties](#properties)
|
34
|
-
- [Typeahead, based on react-bootstrap-typeahead (typeahead)](#typeahead-based-on-react-bootstrap-typeahead-typeahead)
|
35
|
-
- [Purpose](#purpose)
|
36
|
-
- [Use](#use)
|
37
|
-
- [Properties](#properties)
|
38
|
-
- [Label key](#label-key)
|
39
|
-
- [Mapping](#mapping)
|
40
|
-
- [Async Typeahead based on react-bootstrap-typeahead (asyncTypeahead)](#async-typeahead-based-on-react-bootstrap-typeahead-asynctypeahead)
|
41
|
-
- [Purpose](#purpose)
|
42
|
-
- [Use](#use)
|
43
|
-
- [Properties](#properties)
|
44
|
-
- [RTE, based on react-rte (rte)](#rte-based-on-react-rte-rte)
|
45
|
-
- [Purpose](#purpose)
|
46
|
-
- [Use](#use)
|
47
|
-
- [Properties](#properties)
|
48
|
-
- [Tables, based on react-bootstrap-table (table)](#tables-based-on-react-bootstrap-table-table)
|
49
|
-
- [Purpose](#purpose)
|
50
|
-
- [Use](#use)
|
51
|
-
- [Properties](#properties)
|
52
|
-
- [Columns order](#columns-order)
|
53
|
-
- [Cell dataFormat](#cell-dataformat)
|
54
|
-
- [Additional column actions](#additional-column-actions)
|
55
|
-
- [React Day Picker, based on react-day-picker (rdp)](#react-day-picker-based-on-react-day-picker-rdp)
|
56
|
-
- [Purpose](#purpose)
|
57
|
-
- [Use](#use)
|
58
|
-
- [Properties](#properties)
|
59
|
-
- [Contribute](#contribute)
|
60
|
-
- [Support](#support)
|
61
|
-
- [License](#license)
|
62
|
-
|
63
|
-
---
|
64
|
-
|
65
|
-
## Use
|
66
|
-
|
67
|
-
This project uses internal react-jsonschema-form extension mechanism, through ui:field option in uiSchema.
|
68
|
-
The simplest example of using it out of the box, is like this:
|
69
|
-
|
70
|
-
```js
|
71
|
-
import Form from "react-jsonschema-form";
|
72
|
-
import fields from "react-jsonschema-form-extras";
|
73
|
-
|
74
|
-
ReactDOM.render(
|
75
|
-
<Form fields={fields}/>,
|
76
|
-
document.getElementById("app")
|
77
|
-
);
|
78
|
-
|
79
|
-
```
|
80
|
-
|
81
|
-
If you have additional extensions, that are not part of this project, you can enable them, like this
|
82
|
-
|
83
|
-
```js
|
84
|
-
import Form from "react-jsonschema-form";
|
85
|
-
import otherFields from "other-fields";
|
86
|
-
import fields from "react-jsonschema-form-extras";
|
87
|
-
|
88
|
-
let allFields = Object.assign({}, fields, otherFields);
|
89
|
-
|
90
|
-
ReactDOM.render(
|
91
|
-
<Form fields={allFields}/>,
|
92
|
-
document.getElementById("app")
|
93
|
-
);
|
94
|
-
|
95
|
-
```
|
96
|
-
|
97
|
-
You can load only one field you need if want to keep the bundle small.
|
98
|
-
|
99
|
-
```js
|
100
|
-
import Form from "react-jsonschema-form";
|
101
|
-
import { TypeaheadField } from "react-jsonschema-form-extras/lib/TypeaheadField";
|
102
|
-
|
103
|
-
ReactDOM.render(
|
104
|
-
<Form fields={{ typeahead: TypeaheadField }}/>,
|
105
|
-
document.getElementById("app")
|
106
|
-
);
|
107
|
-
```
|
108
|
-
[](https://codesandbox.io/s/p3z45m8rpq)
|
109
|
-
|
110
|
-
If you want multiple fields:
|
111
|
-
|
112
|
-
```js
|
113
|
-
import Form from "react-jsonschema-form";
|
114
|
-
import { TypeaheadField } from "react-jsonschema-form-extras/lib/TypeaheadField";
|
115
|
-
import ReactDatePicker from "react-jsonschema-form-extras/lib/ReactDatePicker";
|
116
|
-
|
117
|
-
ReactDOM.render(
|
118
|
-
<Form fields={{ typeahead: TypeaheadField, rdp: ReactDatePicker }}/>,
|
119
|
-
document.getElementById("app")
|
120
|
-
);
|
121
|
-
```
|
122
|
-
[](https://codesandbox.io/s/wnyl7n07zk)
|
123
|
-
|
124
|
-
## Composite array field (`compositeArray`)
|
125
|
-
|
126
|
-
### Purpose
|
127
|
-
|
128
|
-
This is a simple UI pattern, where you want to separate entering a new value to the array and working with existing values.
|
129
|
-
|
130
|
-
### Use
|
131
|
-
|
132
|
-
The simplest `uiSchema` configuration would be:
|
133
|
-
|
134
|
-
```json
|
135
|
-
{
|
136
|
-
"ui:field": "compositeArray",
|
137
|
-
"inputField": "typeahead",
|
138
|
-
"arrayField": "table",
|
139
|
-
"typeahead": { },
|
140
|
-
"table": { }
|
141
|
-
}
|
142
|
-
```
|
143
|
-
|
144
|
-
This means the final field will be presented in 2 parts
|
145
|
-
- initial input with `typeahead` field
|
146
|
-
- array field in `table` form
|
147
|
-
|
148
|
-
You can specify configurations for each field representation independently.
|
149
|
-
|
150
|
-
### Properties
|
151
|
-
|
152
|
-
There are only 2 properties needed for it to work
|
153
|
-
- `inputField` field from form registry to use as a new field input presentation
|
154
|
-
- `arrayField` field from form registry to use to present existing array values
|
155
|
-
|
156
|
-
## Collapsible fields (`collapsible`)
|
157
|
-
|
158
|
-
### Purpose
|
159
|
-
|
160
|
-
Collapsible helps you to hide content, that might take up too much space on the screen an expand it if user wishes.
|
161
|
-
|
162
|
-
### Use
|
163
|
-
|
164
|
-
The simplest `uiSchema` configuration would be:
|
165
|
-
|
166
|
-
```json
|
167
|
-
{
|
168
|
-
"ui:field": "collapsible",
|
169
|
-
"collapse": {
|
170
|
-
"field": "table"
|
171
|
-
}
|
172
|
-
}
|
173
|
-
```
|
174
|
-
|
175
|
-
This is a hidden `table` field configuration, which will be presented as collapsed `schema` `title` name.
|
176
|
-
|
177
|
-
### Properties
|
178
|
-
|
179
|
-
You can customize presentation of collapsible field, with "collapse" object in uiSchema
|
180
|
-
- `field` `string` an actual hidden field to use
|
181
|
-
- `collapsed` `boolean` - indicating initial state (default `true`)
|
182
|
-
- `icon` `object` icons configuration in `enabled` and `disabled` state
|
183
|
-
- `enabled` `string` icon, when the field is shown (default `glyphicon glyphicon-chevron-down`)
|
184
|
-
- `disabled` `string` icon, when field is hidden (default `glyphicon glyphicon-chevron-right`)
|
185
|
-
- `add` `string` icon, to use in place of an add sign (default `glyphicon glyphicon-plus-sign`)
|
186
|
-
- `separate` `boolean` enable <hr/> after collapse menu (default `true`)
|
187
|
-
- `wrapClassName` `string` class name to use on a parent collapse menu div (default `lead`)
|
188
|
-
- `addTo` `string` array field name, to which icon will be added enables an add icon, that will be shown besides collapsible icon
|
189
|
-
- `addElement` (experimental) representation element for add function (for example if you want to show modal on add icon press, here where this would be)
|
190
|
-
- `function(schema, uiSchema, onChange)` that returns React Component to render for add function
|
191
|
-
- `string` `field` definition from `react-jsonschema-form` catalogue
|
192
|
-
- `actions` (experimental) allows to add additional actions to collapsible menu
|
193
|
-
- `array` of `objects` that allows to render any kind of `action` you need, which will be sourced from `formContext` `allActions` configuration
|
194
|
-
- `component` `string` name of the component, that will be sourced from `formContext.allActions` object
|
195
|
-
- `props` `object` additional properties for rendered component
|
196
|
-
- `legend` (experimental) allows to add additional information under collapsed field
|
197
|
-
- `string` text to be rendered under collapsible field
|
198
|
-
- `object` that allows to render any kind of `legend` you need, which will be sourced from `formContext` `legends` configuration
|
199
|
-
- `component` `string` name of the component, that will be sourced from `formContext.legends` object
|
200
|
-
- `props` `object` additional properties for rendered component
|
201
|
-
|
202
|
-
|
203
|
-
Additional feature of the Collapsible field is to allow adding empty value to hidden `array`, it's enabled with `addTo` feature, which can
|
204
|
-
be either `self` which assumes that Collapsible field is the target array, or it can be a property field.
|
205
|
-
|
206
|
-
Field `schema` `title` used as a header of the collapsible action.
|
207
|
-
|
208
|
-
### Examples
|
209
|
-
|
210
|
-
#### Using specific legend in collapsible field.
|
211
|
-
|
212
|
-
Task:
|
213
|
-
|
214
|
-
We have a `firstName` field, which is collapsible and we need to display a `LanguageLegend`, which would notify user of the language to use.
|
215
|
-
|
216
|
-
Solution:
|
217
|
-
|
218
|
-
The simplest configuration with `schema`, `uiSchema` and `formContext` would look something like this
|
219
|
-
|
220
|
-
```jsx harmony
|
221
|
-
import React from "react";
|
222
|
-
import fields from "react-jsonschema-form-extras"
|
223
|
-
|
224
|
-
let schema = {
|
225
|
-
type: "object",
|
226
|
-
properties: {
|
227
|
-
firstName: { type: "string" }
|
228
|
-
}
|
229
|
-
}
|
230
|
-
|
231
|
-
let uiSchema = {
|
232
|
-
firstName: {
|
233
|
-
"ui:field": "collapsible",
|
234
|
-
collapse: {
|
235
|
-
field: "StringField",
|
236
|
-
legend: {
|
237
|
-
component: "LanguageLegend",
|
238
|
-
props: {
|
239
|
-
language: "EN"
|
240
|
-
}
|
241
|
-
}
|
242
|
-
}
|
243
|
-
}
|
244
|
-
}
|
245
|
-
|
246
|
-
let formContext = {
|
247
|
-
legends: {
|
248
|
-
LanguageLegend: (props) => (<h1>Expected {props.language} characters</h1>)
|
249
|
-
}
|
250
|
-
}
|
251
|
-
|
252
|
-
<Form formContext={formContext} schema={schema} uiSchema={uiSchema} fields={fields}>
|
253
|
-
```
|
254
|
-
|
255
|
-
## Alternative input fields (`altInput`)
|
256
|
-
|
257
|
-
### Purpose
|
258
|
-
|
259
|
-
You want to enter the same `field` in 2 different ways. For example if a field might be a `string` and `number`
|
260
|
-
|
261
|
-
### Use
|
262
|
-
|
263
|
-
The simplest configuration would look something like this
|
264
|
-
|
265
|
-
```json
|
266
|
-
{
|
267
|
-
"ui:field": "altInput",
|
268
|
-
"defInput": "typeahead",
|
269
|
-
"altInput": "asyncTypeahead",
|
270
|
-
"typeahead": { },
|
271
|
-
"asyncTypeahead": { }
|
272
|
-
}
|
273
|
-
```
|
274
|
-
In this case user would be able to enter the same field, either by using async typeahead or regular one.
|
275
|
-
|
276
|
-
### Properties
|
277
|
-
|
278
|
-
In order to configure presentation there are few options
|
279
|
-
- `defInput` `string` registry field to use as primary input method
|
280
|
-
- `altInput` `string` registry field to use as an alternative input method
|
281
|
-
- `altInputSeparator` `string` string to use in between those 2 presentations
|
282
|
-
|
283
|
-
## Typeahead, based on [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead) (`typeahead`)
|
284
|
-
|
285
|
-
### Purpose
|
286
|
-
|
287
|
-
This is a wrap of [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead), which allows you to use this project in your `jsonschema-form`
|
288
|
-
|
289
|
-
### Use
|
290
|
-
|
291
|
-
The simplest configuration would be
|
292
|
-
|
293
|
-
```json
|
294
|
-
{
|
295
|
-
"ui:field": "typeahead",
|
296
|
-
"typeahead": {
|
297
|
-
"options": [ { "state": "New York" }, { "code": "Washington" }],
|
298
|
-
"labelKey": "state"
|
299
|
-
}
|
300
|
-
}
|
301
|
-
```
|
302
|
-
|
303
|
-
In this case the typeahead would only have 2 options - `New York` and `Washigton`
|
304
|
-
|
305
|
-
### Properties
|
306
|
-
|
307
|
-
All properties that you specify under `typeahead` will be used in the original project.
|
308
|
-
- `focusOnMount` focusOn typeahead, after it was mounted to page
|
309
|
-
- `typeahead` all properties that you specify under `typeahead` will be used in the original project.
|
310
|
-
Additionally, there are few project specific properties
|
311
|
-
- `labelKey` have more flexibility in configuration
|
312
|
-
- `labelKey` `string` used a labelKey in [typeahead](https://github.com/ericgio/react-bootstrap-typeahead) project
|
313
|
-
- `labelKey` `array` in this case array is a list of fields in original object, which are combined in a single string with a space separator
|
314
|
-
- `labelKey` `object` with `fields` `array` of fields to use, `separator` string separator to use between fields
|
315
|
-
- `cleanAfterSelection` `boolean` clean selection after component was selected (default false)
|
316
|
-
- `mapping` `object` that maps selected object to schema object
|
317
|
-
|
318
|
-
|
319
|
-
For complete list of configurations refer to [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead)
|
320
|
-
|
321
|
-
Here are some use case examples
|
322
|
-
|
323
|
-
With following options
|
324
|
-
|
325
|
-
```json
|
326
|
-
[
|
327
|
-
{
|
328
|
-
"name": "Adventures of Huckleberry Finn", "author": "Mark Twain"
|
329
|
-
},
|
330
|
-
{
|
331
|
-
"name": "The Adventures of Tom Sawyer", "author": "Mark Twain"
|
332
|
-
}
|
333
|
-
]
|
334
|
-
```
|
335
|
-
|
336
|
-
#### Label key
|
337
|
-
|
338
|
-
With labelKey `name` there will be 2 options
|
339
|
-
- `Adventures of Huckleberry Finn`
|
340
|
-
- `The Adventures of Tom Sawyer`
|
341
|
-
|
342
|
-
With labelKey `[ "author", "name" ]`, options will be
|
343
|
-
- `Mark Twain Adventures of Huckleberry Finn`
|
344
|
-
- `Mark Twain The Adventures of Tom Sawyer`
|
345
|
-
|
346
|
-
With lableKey `{ fields: [ "author", "name" ], separator: " - " }`, options will be
|
347
|
-
- `Mark Twain - Adventures of Huckleberry Finn`
|
348
|
-
- `Mark Twain - The Adventures of Tom Sawyer`
|
349
|
-
|
350
|
-
#### Mapping
|
351
|
-
|
352
|
-
Mapping can be one of
|
353
|
-
- not specified, in this case selection is sent to the formData as is
|
354
|
-
- `string` which is field name in typeahead selected object
|
355
|
-
- `object` with fields corresponding to final schema fields and values, corresponding to fields in typeahead
|
356
|
-
- `function` which will be called with typeahead selected objects, which ever value you specify will be used
|
357
|
-
|
358
|
-
Mapping as undefined (we accept values as is)
|
359
|
-
```
|
360
|
-
{
|
361
|
-
"mapping": undefined
|
362
|
-
}
|
363
|
-
```
|
364
|
-
would result in
|
365
|
-
- `{ "name": "Adventures of Huckleberry Finn", "author": "Mark Twain" }`
|
366
|
-
- `{ "name": "The Adventures of Tom Sawyer", "author": "Mark Twain" }`
|
367
|
-
|
368
|
-
Mapping as string (we want only name of the book)
|
369
|
-
```json
|
370
|
-
{
|
371
|
-
"mapping": "name"
|
372
|
-
}
|
373
|
-
```
|
374
|
-
would result in
|
375
|
-
- `"Adventures of Huckleberry Finn"`
|
376
|
-
- `"The Adventures of Tom Sawyer"`
|
377
|
-
|
378
|
-
|
379
|
-
Mapping as object (we want to change mapping to creator and book)
|
380
|
-
```json
|
381
|
-
{
|
382
|
-
"mapping": {
|
383
|
-
"creator": "author",
|
384
|
-
"book": "name"
|
385
|
-
}
|
386
|
-
}
|
387
|
-
```
|
388
|
-
would result in
|
389
|
-
- `{ book: "Adventures of Huckleberry Finn", creator: "Mark Twain" }`
|
390
|
-
- `{ book: "The Adventures of Tom Sawyer", creator: "Mark Twain" }`
|
391
|
-
|
392
|
-
Mapping as function (let's say we want to take a first name of the author)
|
393
|
-
```js
|
394
|
-
let uiSchema = {
|
395
|
-
mapping: (event) => event.creator.split(" ")[0]
|
396
|
-
}
|
397
|
-
```
|
398
|
-
would result in
|
399
|
-
- `"Mark"`
|
400
|
-
- `"Mark"`
|
401
|
-
|
402
|
-
|
403
|
-
## Async Typeahead based on [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead) (`asyncTypeahead`)
|
404
|
-
|
405
|
-
### Purpose
|
406
|
-
|
407
|
-
This is a wrap around `async` functionality of [typeahead](https://github.com/ericgio/react-bootstrap-typeahead), supporting some additional defaults.
|
408
|
-
|
409
|
-
### Use
|
410
|
-
|
411
|
-
The simplest configuration would be
|
412
|
-
|
413
|
-
```json
|
414
|
-
{
|
415
|
-
"ui:field": "asyncTypeahead",
|
416
|
-
"asyncTypeahead": {
|
417
|
-
"url": "https://example.com/state"
|
418
|
-
}
|
419
|
-
}
|
420
|
-
```
|
421
|
-
|
422
|
-
This will result in typeahead search with `https://example.com/state?query=${query}`
|
423
|
-
|
424
|
-
### Properties
|
425
|
-
|
426
|
-
Async typeahead extends default configuration list for `typeahead`, by adding few properties under `asyncTypeahead`
|
427
|
-
- `focusOnMount` focusOn typeahead, after it was mounted to page
|
428
|
-
- `asyncTypeahead` all properties that you specify under `typeahead` will be used in the original project.
|
429
|
-
- `url` search url, that will be used during autocomplete
|
430
|
-
- `search` function that will be querying server for data, which takes 2 parameters, and must return a Promise with a json result
|
431
|
-
- `url` configured URL
|
432
|
-
- `query` typed query string
|
433
|
-
- `optionsPath` path to options array in response
|
434
|
-
- `labelKey` have more flexibility in configuration
|
435
|
-
- `labelKey` `string` used a labelKey in [typeahead](https://github.com/ericgio/react-bootstrap-typeahead) project
|
436
|
-
- `labelKey` `array` in this case array is a list of fields in original object, which are combined in a single string with a space separator
|
437
|
-
- `labelKey` `object` with `fields` `array` of fields to use, `separator` string separator to use between fields
|
438
|
-
- `cleanAfterSelection` `boolean` clean selection after component was selected (default false)
|
439
|
-
- `overrideOptions` if true, the user can type any text in the input field (or select an option, then modify it),
|
440
|
-
and it will be saved in the RJSF model (default false)
|
441
|
-
- `mapping` `object` that maps selected object to schema object
|
442
|
-
|
443
|
-
|
444
|
-
For example, let's consider query with `Was` on `url` `https://example.com/state`.
|
445
|
-
|
446
|
-
By default field will query results with - `https://example.com/state?query=Was`.
|
447
|
-
|
448
|
-
Let's say we want to override it and query - `https://example.com/state?name=Was&maxSize=1`.
|
449
|
-
|
450
|
-
Here is how we can do that:
|
451
|
-
|
452
|
-
```js
|
453
|
-
let uiSchema = {
|
454
|
-
"ui:field": "asyncTypeahead",
|
455
|
-
asyncTypeahead: {
|
456
|
-
url: "https://example.com/state",
|
457
|
-
search: (url, query) => fetch(`${url}?name=${query}&maxSize=1`)
|
458
|
-
}
|
459
|
-
}
|
460
|
-
```
|
461
|
-
That is it.
|
462
|
-
|
463
|
-
For complete list of async typeahead configurations refer to [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead)
|
464
|
-
|
465
|
-
## RTE, based on [react-rte](https://github.com/sstur/react-rte) (`rte`)
|
466
|
-
|
467
|
-
### Purpose
|
468
|
-
|
469
|
-
This is a simple field, that allows you to enter RTE text inside your string field.
|
470
|
-
|
471
|
-
### Use
|
472
|
-
|
473
|
-
The simplest configuration would be
|
474
|
-
|
475
|
-
```json
|
476
|
-
{
|
477
|
-
"ui:field": "rte",
|
478
|
-
"rte": {
|
479
|
-
"format": "html"
|
480
|
-
}
|
481
|
-
}
|
482
|
-
```
|
483
|
-
|
484
|
-
### Properties
|
485
|
-
|
486
|
-
The only property this field requires is `format`
|
487
|
-
- `format` `string` an `rte` output format (default `html`)
|
488
|
-
- `updateOnBlur` `boolean` allows for RTE update parent form only after edit finished, to minimize calculations and redraw (default `false`)
|
489
|
-
|
490
|
-
As with other projects, all configurations, that you'll configure under `uiSchema` `rte` field will be transferred to the actual component.
|
491
|
-
|
492
|
-
|
493
|
-
## Tables, based on [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table) (`table`)
|
494
|
-
|
495
|
-
### Purpose
|
496
|
-
|
497
|
-
This component wraps [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table) for array components, with smart default configurations.
|
498
|
-
|
499
|
-
### Use
|
500
|
-
|
501
|
-
The simplest configuration would be
|
502
|
-
|
503
|
-
```json
|
504
|
-
{
|
505
|
-
"ui:field": "table"
|
506
|
-
}
|
507
|
-
```
|
508
|
-
|
509
|
-
### Properties
|
510
|
-
|
511
|
-
You can use `table` field without any predefined configurations, it will generate default table schema with columns.
|
512
|
-
- `tableCols` an array of react-bootstrap-table configurations, that override default generated configurations for the field.
|
513
|
-
- `focusOnAdd` column number, when set, adding new row to the table, it will focus on a specified column.
|
514
|
-
|
515
|
-
By default table component will generate table columns, based on an array schema, with editables, based on field types.
|
516
|
-
|
517
|
-
You can reuse react-jsonschema-form Components, in table column editing, to do that, you need to define
|
518
|
-
- `field` property in tableCols override section, with `uiSchema` to use for the field.
|
519
|
-
|
520
|
-
For example let's say we have allergy array, with `allergyName` coming from server source,
|
521
|
-
we can enable `asyncTypeahead` on allergyName field in `tableCols` override like this:
|
522
|
-
```js
|
523
|
-
let uiSchema = {
|
524
|
-
allergies: {
|
525
|
-
classNames: "col-md-12",
|
526
|
-
"ui:field": "table",
|
527
|
-
table: {
|
528
|
-
tableCols: [
|
529
|
-
{
|
530
|
-
dataField: "allergyName",
|
531
|
-
field: "asyncTypeahead",
|
532
|
-
uiSchema: {
|
533
|
-
"ui:field": "asyncTypeahead",
|
534
|
-
asyncTypeahead: {
|
535
|
-
bodyContainer: true,
|
536
|
-
url: "/allergies/typeahead"
|
537
|
-
},
|
538
|
-
},
|
539
|
-
},
|
540
|
-
],
|
541
|
-
},
|
542
|
-
},
|
543
|
-
};
|
544
|
-
```
|
545
|
-
|
546
|
-
#### Columns order
|
547
|
-
|
548
|
-
By default order of columns is defined by `schema` properties field order.
|
549
|
-
It might be not always reliable, so there is a way to override it.
|
550
|
-
By default the order will follow order of columns in `tableCols` configuration.
|
551
|
-
|
552
|
-
|
553
|
-
```js
|
554
|
-
let schema = {
|
555
|
-
type: 'object',
|
556
|
-
properties: {
|
557
|
-
medications: {
|
558
|
-
type: 'array',
|
559
|
-
items: {
|
560
|
-
type: "object",
|
561
|
-
properties: {
|
562
|
-
dosage: { type: "number" },
|
563
|
-
name: { type: "string" }
|
564
|
-
}
|
565
|
-
}
|
566
|
-
}
|
567
|
-
}
|
568
|
-
};
|
569
|
-
|
570
|
-
let uiSchema = {
|
571
|
-
medications: {
|
572
|
-
"ui:field": "table",
|
573
|
-
table: {
|
574
|
-
tableCols: [
|
575
|
-
{
|
576
|
-
dataField: "name",
|
577
|
-
},
|
578
|
-
{
|
579
|
-
dataField: "dosage",
|
580
|
-
},
|
581
|
-
],
|
582
|
-
},
|
583
|
-
},
|
584
|
-
};
|
585
|
-
```
|
586
|
-
|
587
|
-
Here although in medications property schema `dosage` goes before `name`, it will be shown first due to `tableCols` order of columns.
|
588
|
-
|
589
|
-
#### Cell dataFormat
|
590
|
-
|
591
|
-
react-bootstrap-table provides custom [dataFormat](https://allenfang.github.io/react-bootstrap-table/docs.html#dataFormat) for rendering data in columns.
|
592
|
-
We needed to support serialized configuration, so we extended native functionality, with string configuration,
|
593
|
-
- `object` dataFormat can be a `string` which translates into field name in the object.
|
594
|
-
- `date-time` & `date` `string` dataFormat is a format of string presentation, that is generated with moment.js
|
595
|
-
|
596
|
-
For example, let's say we have an allergies table, with identifier, which consists of some numeric id and string name. When showing to the user, we want to show only name. Here is how we can do this:
|
597
|
-
|
598
|
-
```js
|
599
|
-
let schema = {
|
600
|
-
type: 'object',
|
601
|
-
properties: {
|
602
|
-
allergies: {
|
603
|
-
type: 'array',
|
604
|
-
items: {
|
605
|
-
type: "object",
|
606
|
-
properties: {
|
607
|
-
identified: {
|
608
|
-
type: "object",
|
609
|
-
properties: {
|
610
|
-
id: { type: "string"},
|
611
|
-
name: { type: "string" }
|
612
|
-
}
|
613
|
-
},
|
614
|
-
added: { type: "date-time" }
|
615
|
-
}
|
616
|
-
}
|
617
|
-
}
|
618
|
-
}
|
619
|
-
}
|
620
|
-
|
621
|
-
let uiSchema = {
|
622
|
-
medications: {
|
623
|
-
"ui:field": "table",
|
624
|
-
table: {
|
625
|
-
tableCols: [
|
626
|
-
{
|
627
|
-
dataField: "identifier",
|
628
|
-
dataFormat: "name"
|
629
|
-
},
|
630
|
-
{
|
631
|
-
dataField: "dosage",
|
632
|
-
dataFormat: "YYYY-MM-DD"
|
633
|
-
},
|
634
|
-
],
|
635
|
-
},
|
636
|
-
},
|
637
|
-
};
|
638
|
-
```
|
639
|
-
In this case dataFormat on identifier field, will translate into selecting name field in identifier object.
|
640
|
-
|
641
|
-
### Additional column actions
|
642
|
-
|
643
|
-
If you need to define additional column actions to the left or to the right of column content you can do that in
|
644
|
-
a standard way with `uiSchema` with `leftActions` or `rightActions` defined
|
645
|
-
|
646
|
-
```js
|
647
|
-
let uiSchema = {
|
648
|
-
table: {
|
649
|
-
leftActions: [
|
650
|
-
{
|
651
|
-
action: "delete",
|
652
|
-
className: "col-md-1",
|
653
|
-
columnClassName: "col-md-1",
|
654
|
-
editColumnClassName: "col-md-1",
|
655
|
-
icon: "glyphicon glyphicon-minus"
|
656
|
-
}
|
657
|
-
],
|
658
|
-
rightActions: [
|
659
|
-
{
|
660
|
-
action: "delete",
|
661
|
-
icon: "glyphicon glyphicon-minus",
|
662
|
-
text: "Remove"
|
663
|
-
}
|
664
|
-
]
|
665
|
-
}
|
666
|
-
}
|
667
|
-
```
|
668
|
-
|
669
|
-
Both left and right actions can accept full column configuration, that will be appended to the rendered column,
|
670
|
-
|
671
|
-
For example, to define delete on each column, you can:
|
672
|
-
```js
|
673
|
-
let uiSchema = {
|
674
|
-
table: {
|
675
|
-
leftActions: [
|
676
|
-
{
|
677
|
-
dataField: "delete-button",
|
678
|
-
dataFormat: (cell, row, enumObject, rowIndex, formData, onChange) => (
|
679
|
-
<span onClick={() => onChange(formData.filter((el, i) => rowIndex !== i))}>"Remove All"</span>
|
680
|
-
),
|
681
|
-
editable: false,
|
682
|
-
displayName: "Left Panel"
|
683
|
-
},
|
684
|
-
],
|
685
|
-
rightActions: [
|
686
|
-
{
|
687
|
-
action: "delete",
|
688
|
-
icon: "glyphicon glyphicon-minus",
|
689
|
-
text: "Delete",
|
690
|
-
displayName: "Right Panel"
|
691
|
-
}
|
692
|
-
]
|
693
|
-
}
|
694
|
-
}
|
695
|
-
```
|
696
|
-
|
697
|
-
In left panel, we have defined delete with a standard `react-bootstrap-table` format, the only difference is dataFormat signature changed,
|
698
|
-
appending original formData and onChange callback to relay changes to the listening component.
|
699
|
-
|
700
|
-
Right panel is defined with small syntactic sugar to simpify action defintion
|
701
|
-
- `action` can be either `delete` string or function, that is equivalent on onClick function with `cell`, `row`, `enumObject`, `rowIndex`, `formData`, `onChange` parameters
|
702
|
-
- `icon` icon to use for the column
|
703
|
-
- `text` text to use for the column
|
704
|
-
- `displayName` column name
|
705
|
-
|
706
|
-
## React Day Picker, based on [react-day-picker](https://github.com/gpbl/react-day-picker) (`rdp`)
|
707
|
-
|
708
|
-
### Purpose
|
709
|
-
|
710
|
-
Allows you to use react-day-picker as input `ui:field`. This component works only with `string` formatted as `date` and `date-time`.
|
711
|
-
|
712
|
-
### Use
|
713
|
-
|
714
|
-
The simplest configuration would be
|
715
|
-
|
716
|
-
```json
|
717
|
-
{
|
718
|
-
"ui:field": "rdp"
|
719
|
-
}
|
720
|
-
```
|
721
|
-
|
722
|
-
### Properties
|
723
|
-
|
724
|
-
All configurations, that you'll configure under `uiSchema` `rdp` field will be transferred to the actual component.
|
725
|
-
|
726
|
-
For example to enable `Today` button, you would need to specify following uiSchema
|
727
|
-
```json
|
728
|
-
{
|
729
|
-
"ui:field": "rdp",
|
730
|
-
"rdp": {
|
731
|
-
"dayPickerProps": {
|
732
|
-
"todayButton": "Today"
|
733
|
-
}
|
734
|
-
}
|
735
|
-
}
|
736
|
-
|
737
|
-
```
|
738
|
-
For the full list of properties refer to [React Day Picker](http://react-day-picker.js.org).
|
739
|
-
|
740
|
-
|
741
|
-
## Table Expandable Row Component
|
742
|
-
|
743
|
-
### Purpose
|
744
|
-
|
745
|
-
to enable expandable row in table component
|
746
|
-
|
747
|
-
### Use
|
748
|
-
|
749
|
-
to expand table rows
|
750
|
-
```json
|
751
|
-
{
|
752
|
-
"table": {
|
753
|
-
"isTableExpandable":false,
|
754
|
-
"allowOneRowExpanding":true
|
755
|
-
}
|
756
|
-
}
|
757
|
-
```
|
758
|
-
|
759
|
-
### Properties
|
760
|
-
|
761
|
-
All configurations, that you'll configure under `uiSchema` `table` field will be transferred to the actual component.
|
762
|
-
|
763
|
-
For example to enable `ExpandRow` button, you would need to specify following uiSchema
|
764
|
-
```json
|
765
|
-
{
|
766
|
-
"table": {
|
767
|
-
"isTableExpandable":false,
|
768
|
-
"allowOneRowExpanding":true
|
769
|
-
}
|
770
|
-
}
|
771
|
-
|
772
|
-
```
|
773
|
-
|
774
|
-
## Contribute
|
775
|
-
|
776
|
-
- Issue Tracker: github.com/RxNT/react-jsonschema-extras/issues
|
777
|
-
- Source Code: github.com/RxNT/react-jsonschema-extras
|
778
|
-
|
779
|
-
## Support
|
780
|
-
|
781
|
-
If you are having issues, please let us know here or on StackOverflow.
|
782
|
-
|
783
|
-
## License
|
784
|
-
|
785
|
-
The project is licensed under the Apache Licence 2.0.
|
1
|
+
[](https://travis-ci.org/RxNT/react-jsonschema-form-extras)
|
2
|
+
[](https://coveralls.io/github/RxNT/react-jsonschema-form-extras)
|
3
|
+
[](https://badge.fury.io/js/react-jsonschema-form-extras)
|
4
|
+
|
5
|
+
|
6
|
+
# Catalogue
|
7
|
+
|
8
|
+
This project provides light integration over established React components,
|
9
|
+
trying to keep configurations compatible with original project.
|
10
|
+
All configurations you can specify in original projects, can be reused here.
|
11
|
+
|
12
|
+
- Composite array field (`ui:field` > `compositeArray`)
|
13
|
+
- Collapsible fields (`ui:field` > `collapsible`)
|
14
|
+
- Alternative input fields (`ui:field` > `altInput`)
|
15
|
+
- Typeahead, based on [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead) (`ui:field` > `typeahead`)
|
16
|
+
- Async Typeahead based on [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead) (`ui:field` > `asyncTypeahead`)
|
17
|
+
- RTE, based on [react-rte](https://github.com/sstur/react-rte) (`ui:field` > `rte`)
|
18
|
+
- Tables, based on [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table) (`ui:field` > `table`)
|
19
|
+
|
20
|
+
## Table of Contents
|
21
|
+
|
22
|
+
- [Use](#use)
|
23
|
+
- [Composite array field (compositeArray)](#composite-array-field-compositearray)
|
24
|
+
- [Purpose](#purpose)
|
25
|
+
- [Use](#use)
|
26
|
+
- [Properties](#properties)
|
27
|
+
- [Collapsible fields (collapsible)](#collapsible-fields-collapsible)
|
28
|
+
- [Purpose](#purpose)
|
29
|
+
- [Use](#use)
|
30
|
+
- [Properties](#properties)
|
31
|
+
- [Examples](#examples)
|
32
|
+
- [Using specific legend in collapsible field.](#using-specific-legend-in-collapsible-field)
|
33
|
+
- [Properties](#properties)
|
34
|
+
- [Typeahead, based on react-bootstrap-typeahead (typeahead)](#typeahead-based-on-react-bootstrap-typeahead-typeahead)
|
35
|
+
- [Purpose](#purpose)
|
36
|
+
- [Use](#use)
|
37
|
+
- [Properties](#properties)
|
38
|
+
- [Label key](#label-key)
|
39
|
+
- [Mapping](#mapping)
|
40
|
+
- [Async Typeahead based on react-bootstrap-typeahead (asyncTypeahead)](#async-typeahead-based-on-react-bootstrap-typeahead-asynctypeahead)
|
41
|
+
- [Purpose](#purpose)
|
42
|
+
- [Use](#use)
|
43
|
+
- [Properties](#properties)
|
44
|
+
- [RTE, based on react-rte (rte)](#rte-based-on-react-rte-rte)
|
45
|
+
- [Purpose](#purpose)
|
46
|
+
- [Use](#use)
|
47
|
+
- [Properties](#properties)
|
48
|
+
- [Tables, based on react-bootstrap-table (table)](#tables-based-on-react-bootstrap-table-table)
|
49
|
+
- [Purpose](#purpose)
|
50
|
+
- [Use](#use)
|
51
|
+
- [Properties](#properties)
|
52
|
+
- [Columns order](#columns-order)
|
53
|
+
- [Cell dataFormat](#cell-dataformat)
|
54
|
+
- [Additional column actions](#additional-column-actions)
|
55
|
+
- [React Day Picker, based on react-day-picker (rdp)](#react-day-picker-based-on-react-day-picker-rdp)
|
56
|
+
- [Purpose](#purpose)
|
57
|
+
- [Use](#use)
|
58
|
+
- [Properties](#properties)
|
59
|
+
- [Contribute](#contribute)
|
60
|
+
- [Support](#support)
|
61
|
+
- [License](#license)
|
62
|
+
|
63
|
+
---
|
64
|
+
|
65
|
+
## Use
|
66
|
+
|
67
|
+
This project uses internal react-jsonschema-form extension mechanism, through ui:field option in uiSchema.
|
68
|
+
The simplest example of using it out of the box, is like this:
|
69
|
+
|
70
|
+
```js
|
71
|
+
import Form from "react-jsonschema-form";
|
72
|
+
import fields from "react-jsonschema-form-extras";
|
73
|
+
|
74
|
+
ReactDOM.render(
|
75
|
+
<Form fields={fields}/>,
|
76
|
+
document.getElementById("app")
|
77
|
+
);
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
If you have additional extensions, that are not part of this project, you can enable them, like this
|
82
|
+
|
83
|
+
```js
|
84
|
+
import Form from "react-jsonschema-form";
|
85
|
+
import otherFields from "other-fields";
|
86
|
+
import fields from "react-jsonschema-form-extras";
|
87
|
+
|
88
|
+
let allFields = Object.assign({}, fields, otherFields);
|
89
|
+
|
90
|
+
ReactDOM.render(
|
91
|
+
<Form fields={allFields}/>,
|
92
|
+
document.getElementById("app")
|
93
|
+
);
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
You can load only one field you need if want to keep the bundle small.
|
98
|
+
|
99
|
+
```js
|
100
|
+
import Form from "react-jsonschema-form";
|
101
|
+
import { TypeaheadField } from "react-jsonschema-form-extras/lib/TypeaheadField";
|
102
|
+
|
103
|
+
ReactDOM.render(
|
104
|
+
<Form fields={{ typeahead: TypeaheadField }}/>,
|
105
|
+
document.getElementById("app")
|
106
|
+
);
|
107
|
+
```
|
108
|
+
[](https://codesandbox.io/s/p3z45m8rpq)
|
109
|
+
|
110
|
+
If you want multiple fields:
|
111
|
+
|
112
|
+
```js
|
113
|
+
import Form from "react-jsonschema-form";
|
114
|
+
import { TypeaheadField } from "react-jsonschema-form-extras/lib/TypeaheadField";
|
115
|
+
import ReactDatePicker from "react-jsonschema-form-extras/lib/ReactDatePicker";
|
116
|
+
|
117
|
+
ReactDOM.render(
|
118
|
+
<Form fields={{ typeahead: TypeaheadField, rdp: ReactDatePicker }}/>,
|
119
|
+
document.getElementById("app")
|
120
|
+
);
|
121
|
+
```
|
122
|
+
[](https://codesandbox.io/s/wnyl7n07zk)
|
123
|
+
|
124
|
+
## Composite array field (`compositeArray`)
|
125
|
+
|
126
|
+
### Purpose
|
127
|
+
|
128
|
+
This is a simple UI pattern, where you want to separate entering a new value to the array and working with existing values.
|
129
|
+
|
130
|
+
### Use
|
131
|
+
|
132
|
+
The simplest `uiSchema` configuration would be:
|
133
|
+
|
134
|
+
```json
|
135
|
+
{
|
136
|
+
"ui:field": "compositeArray",
|
137
|
+
"inputField": "typeahead",
|
138
|
+
"arrayField": "table",
|
139
|
+
"typeahead": { },
|
140
|
+
"table": { }
|
141
|
+
}
|
142
|
+
```
|
143
|
+
|
144
|
+
This means the final field will be presented in 2 parts
|
145
|
+
- initial input with `typeahead` field
|
146
|
+
- array field in `table` form
|
147
|
+
|
148
|
+
You can specify configurations for each field representation independently.
|
149
|
+
|
150
|
+
### Properties
|
151
|
+
|
152
|
+
There are only 2 properties needed for it to work
|
153
|
+
- `inputField` field from form registry to use as a new field input presentation
|
154
|
+
- `arrayField` field from form registry to use to present existing array values
|
155
|
+
|
156
|
+
## Collapsible fields (`collapsible`)
|
157
|
+
|
158
|
+
### Purpose
|
159
|
+
|
160
|
+
Collapsible helps you to hide content, that might take up too much space on the screen an expand it if user wishes.
|
161
|
+
|
162
|
+
### Use
|
163
|
+
|
164
|
+
The simplest `uiSchema` configuration would be:
|
165
|
+
|
166
|
+
```json
|
167
|
+
{
|
168
|
+
"ui:field": "collapsible",
|
169
|
+
"collapse": {
|
170
|
+
"field": "table"
|
171
|
+
}
|
172
|
+
}
|
173
|
+
```
|
174
|
+
|
175
|
+
This is a hidden `table` field configuration, which will be presented as collapsed `schema` `title` name.
|
176
|
+
|
177
|
+
### Properties
|
178
|
+
|
179
|
+
You can customize presentation of collapsible field, with "collapse" object in uiSchema
|
180
|
+
- `field` `string` an actual hidden field to use
|
181
|
+
- `collapsed` `boolean` - indicating initial state (default `true`)
|
182
|
+
- `icon` `object` icons configuration in `enabled` and `disabled` state
|
183
|
+
- `enabled` `string` icon, when the field is shown (default `glyphicon glyphicon-chevron-down`)
|
184
|
+
- `disabled` `string` icon, when field is hidden (default `glyphicon glyphicon-chevron-right`)
|
185
|
+
- `add` `string` icon, to use in place of an add sign (default `glyphicon glyphicon-plus-sign`)
|
186
|
+
- `separate` `boolean` enable <hr/> after collapse menu (default `true`)
|
187
|
+
- `wrapClassName` `string` class name to use on a parent collapse menu div (default `lead`)
|
188
|
+
- `addTo` `string` array field name, to which icon will be added enables an add icon, that will be shown besides collapsible icon
|
189
|
+
- `addElement` (experimental) representation element for add function (for example if you want to show modal on add icon press, here where this would be)
|
190
|
+
- `function(schema, uiSchema, onChange)` that returns React Component to render for add function
|
191
|
+
- `string` `field` definition from `react-jsonschema-form` catalogue
|
192
|
+
- `actions` (experimental) allows to add additional actions to collapsible menu
|
193
|
+
- `array` of `objects` that allows to render any kind of `action` you need, which will be sourced from `formContext` `allActions` configuration
|
194
|
+
- `component` `string` name of the component, that will be sourced from `formContext.allActions` object
|
195
|
+
- `props` `object` additional properties for rendered component
|
196
|
+
- `legend` (experimental) allows to add additional information under collapsed field
|
197
|
+
- `string` text to be rendered under collapsible field
|
198
|
+
- `object` that allows to render any kind of `legend` you need, which will be sourced from `formContext` `legends` configuration
|
199
|
+
- `component` `string` name of the component, that will be sourced from `formContext.legends` object
|
200
|
+
- `props` `object` additional properties for rendered component
|
201
|
+
|
202
|
+
|
203
|
+
Additional feature of the Collapsible field is to allow adding empty value to hidden `array`, it's enabled with `addTo` feature, which can
|
204
|
+
be either `self` which assumes that Collapsible field is the target array, or it can be a property field.
|
205
|
+
|
206
|
+
Field `schema` `title` used as a header of the collapsible action.
|
207
|
+
|
208
|
+
### Examples
|
209
|
+
|
210
|
+
#### Using specific legend in collapsible field.
|
211
|
+
|
212
|
+
Task:
|
213
|
+
|
214
|
+
We have a `firstName` field, which is collapsible and we need to display a `LanguageLegend`, which would notify user of the language to use.
|
215
|
+
|
216
|
+
Solution:
|
217
|
+
|
218
|
+
The simplest configuration with `schema`, `uiSchema` and `formContext` would look something like this
|
219
|
+
|
220
|
+
```jsx harmony
|
221
|
+
import React from "react";
|
222
|
+
import fields from "react-jsonschema-form-extras"
|
223
|
+
|
224
|
+
let schema = {
|
225
|
+
type: "object",
|
226
|
+
properties: {
|
227
|
+
firstName: { type: "string" }
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
let uiSchema = {
|
232
|
+
firstName: {
|
233
|
+
"ui:field": "collapsible",
|
234
|
+
collapse: {
|
235
|
+
field: "StringField",
|
236
|
+
legend: {
|
237
|
+
component: "LanguageLegend",
|
238
|
+
props: {
|
239
|
+
language: "EN"
|
240
|
+
}
|
241
|
+
}
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
let formContext = {
|
247
|
+
legends: {
|
248
|
+
LanguageLegend: (props) => (<h1>Expected {props.language} characters</h1>)
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
<Form formContext={formContext} schema={schema} uiSchema={uiSchema} fields={fields}>
|
253
|
+
```
|
254
|
+
|
255
|
+
## Alternative input fields (`altInput`)
|
256
|
+
|
257
|
+
### Purpose
|
258
|
+
|
259
|
+
You want to enter the same `field` in 2 different ways. For example if a field might be a `string` and `number`
|
260
|
+
|
261
|
+
### Use
|
262
|
+
|
263
|
+
The simplest configuration would look something like this
|
264
|
+
|
265
|
+
```json
|
266
|
+
{
|
267
|
+
"ui:field": "altInput",
|
268
|
+
"defInput": "typeahead",
|
269
|
+
"altInput": "asyncTypeahead",
|
270
|
+
"typeahead": { },
|
271
|
+
"asyncTypeahead": { }
|
272
|
+
}
|
273
|
+
```
|
274
|
+
In this case user would be able to enter the same field, either by using async typeahead or regular one.
|
275
|
+
|
276
|
+
### Properties
|
277
|
+
|
278
|
+
In order to configure presentation there are few options
|
279
|
+
- `defInput` `string` registry field to use as primary input method
|
280
|
+
- `altInput` `string` registry field to use as an alternative input method
|
281
|
+
- `altInputSeparator` `string` string to use in between those 2 presentations
|
282
|
+
|
283
|
+
## Typeahead, based on [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead) (`typeahead`)
|
284
|
+
|
285
|
+
### Purpose
|
286
|
+
|
287
|
+
This is a wrap of [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead), which allows you to use this project in your `jsonschema-form`
|
288
|
+
|
289
|
+
### Use
|
290
|
+
|
291
|
+
The simplest configuration would be
|
292
|
+
|
293
|
+
```json
|
294
|
+
{
|
295
|
+
"ui:field": "typeahead",
|
296
|
+
"typeahead": {
|
297
|
+
"options": [ { "state": "New York" }, { "code": "Washington" }],
|
298
|
+
"labelKey": "state"
|
299
|
+
}
|
300
|
+
}
|
301
|
+
```
|
302
|
+
|
303
|
+
In this case the typeahead would only have 2 options - `New York` and `Washigton`
|
304
|
+
|
305
|
+
### Properties
|
306
|
+
|
307
|
+
All properties that you specify under `typeahead` will be used in the original project.
|
308
|
+
- `focusOnMount` focusOn typeahead, after it was mounted to page
|
309
|
+
- `typeahead` all properties that you specify under `typeahead` will be used in the original project.
|
310
|
+
Additionally, there are few project specific properties
|
311
|
+
- `labelKey` have more flexibility in configuration
|
312
|
+
- `labelKey` `string` used a labelKey in [typeahead](https://github.com/ericgio/react-bootstrap-typeahead) project
|
313
|
+
- `labelKey` `array` in this case array is a list of fields in original object, which are combined in a single string with a space separator
|
314
|
+
- `labelKey` `object` with `fields` `array` of fields to use, `separator` string separator to use between fields
|
315
|
+
- `cleanAfterSelection` `boolean` clean selection after component was selected (default false)
|
316
|
+
- `mapping` `object` that maps selected object to schema object
|
317
|
+
|
318
|
+
|
319
|
+
For complete list of configurations refer to [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead)
|
320
|
+
|
321
|
+
Here are some use case examples
|
322
|
+
|
323
|
+
With following options
|
324
|
+
|
325
|
+
```json
|
326
|
+
[
|
327
|
+
{
|
328
|
+
"name": "Adventures of Huckleberry Finn", "author": "Mark Twain"
|
329
|
+
},
|
330
|
+
{
|
331
|
+
"name": "The Adventures of Tom Sawyer", "author": "Mark Twain"
|
332
|
+
}
|
333
|
+
]
|
334
|
+
```
|
335
|
+
|
336
|
+
#### Label key
|
337
|
+
|
338
|
+
With labelKey `name` there will be 2 options
|
339
|
+
- `Adventures of Huckleberry Finn`
|
340
|
+
- `The Adventures of Tom Sawyer`
|
341
|
+
|
342
|
+
With labelKey `[ "author", "name" ]`, options will be
|
343
|
+
- `Mark Twain Adventures of Huckleberry Finn`
|
344
|
+
- `Mark Twain The Adventures of Tom Sawyer`
|
345
|
+
|
346
|
+
With lableKey `{ fields: [ "author", "name" ], separator: " - " }`, options will be
|
347
|
+
- `Mark Twain - Adventures of Huckleberry Finn`
|
348
|
+
- `Mark Twain - The Adventures of Tom Sawyer`
|
349
|
+
|
350
|
+
#### Mapping
|
351
|
+
|
352
|
+
Mapping can be one of
|
353
|
+
- not specified, in this case selection is sent to the formData as is
|
354
|
+
- `string` which is field name in typeahead selected object
|
355
|
+
- `object` with fields corresponding to final schema fields and values, corresponding to fields in typeahead
|
356
|
+
- `function` which will be called with typeahead selected objects, which ever value you specify will be used
|
357
|
+
|
358
|
+
Mapping as undefined (we accept values as is)
|
359
|
+
```
|
360
|
+
{
|
361
|
+
"mapping": undefined
|
362
|
+
}
|
363
|
+
```
|
364
|
+
would result in
|
365
|
+
- `{ "name": "Adventures of Huckleberry Finn", "author": "Mark Twain" }`
|
366
|
+
- `{ "name": "The Adventures of Tom Sawyer", "author": "Mark Twain" }`
|
367
|
+
|
368
|
+
Mapping as string (we want only name of the book)
|
369
|
+
```json
|
370
|
+
{
|
371
|
+
"mapping": "name"
|
372
|
+
}
|
373
|
+
```
|
374
|
+
would result in
|
375
|
+
- `"Adventures of Huckleberry Finn"`
|
376
|
+
- `"The Adventures of Tom Sawyer"`
|
377
|
+
|
378
|
+
|
379
|
+
Mapping as object (we want to change mapping to creator and book)
|
380
|
+
```json
|
381
|
+
{
|
382
|
+
"mapping": {
|
383
|
+
"creator": "author",
|
384
|
+
"book": "name"
|
385
|
+
}
|
386
|
+
}
|
387
|
+
```
|
388
|
+
would result in
|
389
|
+
- `{ book: "Adventures of Huckleberry Finn", creator: "Mark Twain" }`
|
390
|
+
- `{ book: "The Adventures of Tom Sawyer", creator: "Mark Twain" }`
|
391
|
+
|
392
|
+
Mapping as function (let's say we want to take a first name of the author)
|
393
|
+
```js
|
394
|
+
let uiSchema = {
|
395
|
+
mapping: (event) => event.creator.split(" ")[0]
|
396
|
+
}
|
397
|
+
```
|
398
|
+
would result in
|
399
|
+
- `"Mark"`
|
400
|
+
- `"Mark"`
|
401
|
+
|
402
|
+
|
403
|
+
## Async Typeahead based on [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead) (`asyncTypeahead`)
|
404
|
+
|
405
|
+
### Purpose
|
406
|
+
|
407
|
+
This is a wrap around `async` functionality of [typeahead](https://github.com/ericgio/react-bootstrap-typeahead), supporting some additional defaults.
|
408
|
+
|
409
|
+
### Use
|
410
|
+
|
411
|
+
The simplest configuration would be
|
412
|
+
|
413
|
+
```json
|
414
|
+
{
|
415
|
+
"ui:field": "asyncTypeahead",
|
416
|
+
"asyncTypeahead": {
|
417
|
+
"url": "https://example.com/state"
|
418
|
+
}
|
419
|
+
}
|
420
|
+
```
|
421
|
+
|
422
|
+
This will result in typeahead search with `https://example.com/state?query=${query}`
|
423
|
+
|
424
|
+
### Properties
|
425
|
+
|
426
|
+
Async typeahead extends default configuration list for `typeahead`, by adding few properties under `asyncTypeahead`
|
427
|
+
- `focusOnMount` focusOn typeahead, after it was mounted to page
|
428
|
+
- `asyncTypeahead` all properties that you specify under `typeahead` will be used in the original project.
|
429
|
+
- `url` search url, that will be used during autocomplete
|
430
|
+
- `search` function that will be querying server for data, which takes 2 parameters, and must return a Promise with a json result
|
431
|
+
- `url` configured URL
|
432
|
+
- `query` typed query string
|
433
|
+
- `optionsPath` path to options array in response
|
434
|
+
- `labelKey` have more flexibility in configuration
|
435
|
+
- `labelKey` `string` used a labelKey in [typeahead](https://github.com/ericgio/react-bootstrap-typeahead) project
|
436
|
+
- `labelKey` `array` in this case array is a list of fields in original object, which are combined in a single string with a space separator
|
437
|
+
- `labelKey` `object` with `fields` `array` of fields to use, `separator` string separator to use between fields
|
438
|
+
- `cleanAfterSelection` `boolean` clean selection after component was selected (default false)
|
439
|
+
- `overrideOptions` if true, the user can type any text in the input field (or select an option, then modify it),
|
440
|
+
and it will be saved in the RJSF model (default false)
|
441
|
+
- `mapping` `object` that maps selected object to schema object
|
442
|
+
|
443
|
+
|
444
|
+
For example, let's consider query with `Was` on `url` `https://example.com/state`.
|
445
|
+
|
446
|
+
By default field will query results with - `https://example.com/state?query=Was`.
|
447
|
+
|
448
|
+
Let's say we want to override it and query - `https://example.com/state?name=Was&maxSize=1`.
|
449
|
+
|
450
|
+
Here is how we can do that:
|
451
|
+
|
452
|
+
```js
|
453
|
+
let uiSchema = {
|
454
|
+
"ui:field": "asyncTypeahead",
|
455
|
+
asyncTypeahead: {
|
456
|
+
url: "https://example.com/state",
|
457
|
+
search: (url, query) => fetch(`${url}?name=${query}&maxSize=1`)
|
458
|
+
}
|
459
|
+
}
|
460
|
+
```
|
461
|
+
That is it.
|
462
|
+
|
463
|
+
For complete list of async typeahead configurations refer to [react-bootstrap-typeahead](https://github.com/ericgio/react-bootstrap-typeahead)
|
464
|
+
|
465
|
+
## RTE, based on [react-rte](https://github.com/sstur/react-rte) (`rte`)
|
466
|
+
|
467
|
+
### Purpose
|
468
|
+
|
469
|
+
This is a simple field, that allows you to enter RTE text inside your string field.
|
470
|
+
|
471
|
+
### Use
|
472
|
+
|
473
|
+
The simplest configuration would be
|
474
|
+
|
475
|
+
```json
|
476
|
+
{
|
477
|
+
"ui:field": "rte",
|
478
|
+
"rte": {
|
479
|
+
"format": "html"
|
480
|
+
}
|
481
|
+
}
|
482
|
+
```
|
483
|
+
|
484
|
+
### Properties
|
485
|
+
|
486
|
+
The only property this field requires is `format`
|
487
|
+
- `format` `string` an `rte` output format (default `html`)
|
488
|
+
- `updateOnBlur` `boolean` allows for RTE update parent form only after edit finished, to minimize calculations and redraw (default `false`)
|
489
|
+
|
490
|
+
As with other projects, all configurations, that you'll configure under `uiSchema` `rte` field will be transferred to the actual component.
|
491
|
+
|
492
|
+
|
493
|
+
## Tables, based on [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table) (`table`)
|
494
|
+
|
495
|
+
### Purpose
|
496
|
+
|
497
|
+
This component wraps [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table) for array components, with smart default configurations.
|
498
|
+
|
499
|
+
### Use
|
500
|
+
|
501
|
+
The simplest configuration would be
|
502
|
+
|
503
|
+
```json
|
504
|
+
{
|
505
|
+
"ui:field": "table"
|
506
|
+
}
|
507
|
+
```
|
508
|
+
|
509
|
+
### Properties
|
510
|
+
|
511
|
+
You can use `table` field without any predefined configurations, it will generate default table schema with columns.
|
512
|
+
- `tableCols` an array of react-bootstrap-table configurations, that override default generated configurations for the field.
|
513
|
+
- `focusOnAdd` column number, when set, adding new row to the table, it will focus on a specified column.
|
514
|
+
|
515
|
+
By default table component will generate table columns, based on an array schema, with editables, based on field types.
|
516
|
+
|
517
|
+
You can reuse react-jsonschema-form Components, in table column editing, to do that, you need to define
|
518
|
+
- `field` property in tableCols override section, with `uiSchema` to use for the field.
|
519
|
+
|
520
|
+
For example let's say we have allergy array, with `allergyName` coming from server source,
|
521
|
+
we can enable `asyncTypeahead` on allergyName field in `tableCols` override like this:
|
522
|
+
```js
|
523
|
+
let uiSchema = {
|
524
|
+
allergies: {
|
525
|
+
classNames: "col-md-12",
|
526
|
+
"ui:field": "table",
|
527
|
+
table: {
|
528
|
+
tableCols: [
|
529
|
+
{
|
530
|
+
dataField: "allergyName",
|
531
|
+
field: "asyncTypeahead",
|
532
|
+
uiSchema: {
|
533
|
+
"ui:field": "asyncTypeahead",
|
534
|
+
asyncTypeahead: {
|
535
|
+
bodyContainer: true,
|
536
|
+
url: "/allergies/typeahead"
|
537
|
+
},
|
538
|
+
},
|
539
|
+
},
|
540
|
+
],
|
541
|
+
},
|
542
|
+
},
|
543
|
+
};
|
544
|
+
```
|
545
|
+
|
546
|
+
#### Columns order
|
547
|
+
|
548
|
+
By default order of columns is defined by `schema` properties field order.
|
549
|
+
It might be not always reliable, so there is a way to override it.
|
550
|
+
By default the order will follow order of columns in `tableCols` configuration.
|
551
|
+
|
552
|
+
|
553
|
+
```js
|
554
|
+
let schema = {
|
555
|
+
type: 'object',
|
556
|
+
properties: {
|
557
|
+
medications: {
|
558
|
+
type: 'array',
|
559
|
+
items: {
|
560
|
+
type: "object",
|
561
|
+
properties: {
|
562
|
+
dosage: { type: "number" },
|
563
|
+
name: { type: "string" }
|
564
|
+
}
|
565
|
+
}
|
566
|
+
}
|
567
|
+
}
|
568
|
+
};
|
569
|
+
|
570
|
+
let uiSchema = {
|
571
|
+
medications: {
|
572
|
+
"ui:field": "table",
|
573
|
+
table: {
|
574
|
+
tableCols: [
|
575
|
+
{
|
576
|
+
dataField: "name",
|
577
|
+
},
|
578
|
+
{
|
579
|
+
dataField: "dosage",
|
580
|
+
},
|
581
|
+
],
|
582
|
+
},
|
583
|
+
},
|
584
|
+
};
|
585
|
+
```
|
586
|
+
|
587
|
+
Here although in medications property schema `dosage` goes before `name`, it will be shown first due to `tableCols` order of columns.
|
588
|
+
|
589
|
+
#### Cell dataFormat
|
590
|
+
|
591
|
+
react-bootstrap-table provides custom [dataFormat](https://allenfang.github.io/react-bootstrap-table/docs.html#dataFormat) for rendering data in columns.
|
592
|
+
We needed to support serialized configuration, so we extended native functionality, with string configuration,
|
593
|
+
- `object` dataFormat can be a `string` which translates into field name in the object.
|
594
|
+
- `date-time` & `date` `string` dataFormat is a format of string presentation, that is generated with moment.js
|
595
|
+
|
596
|
+
For example, let's say we have an allergies table, with identifier, which consists of some numeric id and string name. When showing to the user, we want to show only name. Here is how we can do this:
|
597
|
+
|
598
|
+
```js
|
599
|
+
let schema = {
|
600
|
+
type: 'object',
|
601
|
+
properties: {
|
602
|
+
allergies: {
|
603
|
+
type: 'array',
|
604
|
+
items: {
|
605
|
+
type: "object",
|
606
|
+
properties: {
|
607
|
+
identified: {
|
608
|
+
type: "object",
|
609
|
+
properties: {
|
610
|
+
id: { type: "string"},
|
611
|
+
name: { type: "string" }
|
612
|
+
}
|
613
|
+
},
|
614
|
+
added: { type: "date-time" }
|
615
|
+
}
|
616
|
+
}
|
617
|
+
}
|
618
|
+
}
|
619
|
+
}
|
620
|
+
|
621
|
+
let uiSchema = {
|
622
|
+
medications: {
|
623
|
+
"ui:field": "table",
|
624
|
+
table: {
|
625
|
+
tableCols: [
|
626
|
+
{
|
627
|
+
dataField: "identifier",
|
628
|
+
dataFormat: "name"
|
629
|
+
},
|
630
|
+
{
|
631
|
+
dataField: "dosage",
|
632
|
+
dataFormat: "YYYY-MM-DD"
|
633
|
+
},
|
634
|
+
],
|
635
|
+
},
|
636
|
+
},
|
637
|
+
};
|
638
|
+
```
|
639
|
+
In this case dataFormat on identifier field, will translate into selecting name field in identifier object.
|
640
|
+
|
641
|
+
### Additional column actions
|
642
|
+
|
643
|
+
If you need to define additional column actions to the left or to the right of column content you can do that in
|
644
|
+
a standard way with `uiSchema` with `leftActions` or `rightActions` defined
|
645
|
+
|
646
|
+
```js
|
647
|
+
let uiSchema = {
|
648
|
+
table: {
|
649
|
+
leftActions: [
|
650
|
+
{
|
651
|
+
action: "delete",
|
652
|
+
className: "col-md-1",
|
653
|
+
columnClassName: "col-md-1",
|
654
|
+
editColumnClassName: "col-md-1",
|
655
|
+
icon: "glyphicon glyphicon-minus"
|
656
|
+
}
|
657
|
+
],
|
658
|
+
rightActions: [
|
659
|
+
{
|
660
|
+
action: "delete",
|
661
|
+
icon: "glyphicon glyphicon-minus",
|
662
|
+
text: "Remove"
|
663
|
+
}
|
664
|
+
]
|
665
|
+
}
|
666
|
+
}
|
667
|
+
```
|
668
|
+
|
669
|
+
Both left and right actions can accept full column configuration, that will be appended to the rendered column,
|
670
|
+
|
671
|
+
For example, to define delete on each column, you can:
|
672
|
+
```js
|
673
|
+
let uiSchema = {
|
674
|
+
table: {
|
675
|
+
leftActions: [
|
676
|
+
{
|
677
|
+
dataField: "delete-button",
|
678
|
+
dataFormat: (cell, row, enumObject, rowIndex, formData, onChange) => (
|
679
|
+
<span onClick={() => onChange(formData.filter((el, i) => rowIndex !== i))}>"Remove All"</span>
|
680
|
+
),
|
681
|
+
editable: false,
|
682
|
+
displayName: "Left Panel"
|
683
|
+
},
|
684
|
+
],
|
685
|
+
rightActions: [
|
686
|
+
{
|
687
|
+
action: "delete",
|
688
|
+
icon: "glyphicon glyphicon-minus",
|
689
|
+
text: "Delete",
|
690
|
+
displayName: "Right Panel"
|
691
|
+
}
|
692
|
+
]
|
693
|
+
}
|
694
|
+
}
|
695
|
+
```
|
696
|
+
|
697
|
+
In left panel, we have defined delete with a standard `react-bootstrap-table` format, the only difference is dataFormat signature changed,
|
698
|
+
appending original formData and onChange callback to relay changes to the listening component.
|
699
|
+
|
700
|
+
Right panel is defined with small syntactic sugar to simpify action defintion
|
701
|
+
- `action` can be either `delete` string or function, that is equivalent on onClick function with `cell`, `row`, `enumObject`, `rowIndex`, `formData`, `onChange` parameters
|
702
|
+
- `icon` icon to use for the column
|
703
|
+
- `text` text to use for the column
|
704
|
+
- `displayName` column name
|
705
|
+
|
706
|
+
## React Day Picker, based on [react-day-picker](https://github.com/gpbl/react-day-picker) (`rdp`)
|
707
|
+
|
708
|
+
### Purpose
|
709
|
+
|
710
|
+
Allows you to use react-day-picker as input `ui:field`. This component works only with `string` formatted as `date` and `date-time`.
|
711
|
+
|
712
|
+
### Use
|
713
|
+
|
714
|
+
The simplest configuration would be
|
715
|
+
|
716
|
+
```json
|
717
|
+
{
|
718
|
+
"ui:field": "rdp"
|
719
|
+
}
|
720
|
+
```
|
721
|
+
|
722
|
+
### Properties
|
723
|
+
|
724
|
+
All configurations, that you'll configure under `uiSchema` `rdp` field will be transferred to the actual component.
|
725
|
+
|
726
|
+
For example to enable `Today` button, you would need to specify following uiSchema
|
727
|
+
```json
|
728
|
+
{
|
729
|
+
"ui:field": "rdp",
|
730
|
+
"rdp": {
|
731
|
+
"dayPickerProps": {
|
732
|
+
"todayButton": "Today"
|
733
|
+
}
|
734
|
+
}
|
735
|
+
}
|
736
|
+
|
737
|
+
```
|
738
|
+
For the full list of properties refer to [React Day Picker](http://react-day-picker.js.org).
|
739
|
+
|
740
|
+
|
741
|
+
## Table Expandable Row Component
|
742
|
+
|
743
|
+
### Purpose
|
744
|
+
|
745
|
+
to enable expandable row in table component
|
746
|
+
|
747
|
+
### Use
|
748
|
+
|
749
|
+
to expand table rows
|
750
|
+
```json
|
751
|
+
{
|
752
|
+
"table": {
|
753
|
+
"isTableExpandable":false,
|
754
|
+
"allowOneRowExpanding":true
|
755
|
+
}
|
756
|
+
}
|
757
|
+
```
|
758
|
+
|
759
|
+
### Properties
|
760
|
+
|
761
|
+
All configurations, that you'll configure under `uiSchema` `table` field will be transferred to the actual component.
|
762
|
+
|
763
|
+
For example to enable `ExpandRow` button, you would need to specify following uiSchema
|
764
|
+
```json
|
765
|
+
{
|
766
|
+
"table": {
|
767
|
+
"isTableExpandable":false,
|
768
|
+
"allowOneRowExpanding":true
|
769
|
+
}
|
770
|
+
}
|
771
|
+
|
772
|
+
```
|
773
|
+
|
774
|
+
## Contribute
|
775
|
+
|
776
|
+
- Issue Tracker: github.com/RxNT/react-jsonschema-extras/issues
|
777
|
+
- Source Code: github.com/RxNT/react-jsonschema-extras
|
778
|
+
|
779
|
+
## Support
|
780
|
+
|
781
|
+
If you are having issues, please let us know here or on StackOverflow.
|
782
|
+
|
783
|
+
## License
|
784
|
+
|
785
|
+
The project is licensed under the Apache Licence 2.0.
|