jedison 0.2.1 → 0.2.2

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 CHANGED
@@ -12,1918 +12,98 @@ Test and experiment with configuration options in a live environment.
12
12
  📖 **[Documentation](https://germanbisurgi.github.io/jedison-docs/)**
13
13
  Learn how to use Jedison with detailed guides and interactive examples.
14
14
 
15
- # Table of Contents
15
+ # Jedison
16
+
17
+ Jedison helps you validate JSON data on the backend and generate interactive forms from JSON Schemas on the frontend.
18
+
19
+ One common workflow looks like this:
16
20
 
17
- - [Key Features](#key-features)
18
- - [Getting Started](#getting-started)
19
- - [As a Validator](#as-a-validator)
20
- - [As an Editor](#as-an-editor)
21
- - [Instance Methods](#instance-methods)
22
- - [Instance event listeners](#instance-event-listeners)
23
- - [RefParser](#refParser)
24
- - [Instance Options](#instance-options)
25
- - [Editors](#editors)
26
- - [Array](#array-editors)
27
- - [Array](#array-list)
28
- - [Array checkboxes](#array-checkboxes)
29
- - [Array choices](#array-choices)
30
- - [Array nav](#array-nav)
31
- - [Array table](#array-table)
32
- - [Boolean](#boolean-editors)
33
- - [Boolean checkbox](#boolean-checkbox)
34
- - [Boolean radios](#boolean-radios)
35
- - [Boolean select](#boolean-select)
36
- - [Number](#number-editors)
37
- - [Number input](#number-input)
38
- - [Number radios](#number-radios)
39
- - [Number select](#number-select)
40
- - [Number select](#number-select)
41
- - [Object](#object-editors)
42
- - [Object select](#object)
43
- - [Object grid](#object-grid)
44
- - [Object nav](#object-nav)
45
- - [String](#string-editors)
46
- - [String input](#string-input)
47
- - [String radios](#string-radios)
48
- - [String select](#string-select)
49
- - [String textarea](#string-textarea)
50
- - [String IMask](#string-imask)
51
- - [Null](#null-editors)
52
- - [Null](#null)
53
- - [Language and Translations](#language-and-translations)
54
- - [Annotations](#annotations)
55
- - [Markdown](#markdown)
56
- - [Schema Options](#schema-options)
57
- - [x-addPropertyContent](#x-addPropertyContent)
58
- - [x-arrayAdd](#x-arrayAdd)
59
- - [x-arrayAddContent](#x-arrayAddContent)
60
- - [x-arrayDelete](#x-arrayDelete)
61
- - [x-arrayDeleteContent](#x-arrayDeleteContent)
62
- - [x-arrayDragContent](#x-arrayDragContent)
63
- - [x-arrayMove](#x-arrayMove)
64
- - [x-arrayMoveDownContent](#x-arrayMoveDownContent)
65
- - [x-arrayMoveUpContent](#x-arrayMoveUpContent)
66
- - [x-assertFormat](#x-assertformat)
67
- - [x-collapseToggleContent](#x-collapseToggleContent)
68
- - [x-containerAttributes](#x-containerAttributes)
69
- - [x-deactivateNonRequired](#x-deactivateNonRequired)
70
- - [x-enableCollapseToggle](#x-enableCollapseToggle)
71
- - [x-enforceConst](#x-enforceconst)
72
- - [x-enforceEnum](#x-enforceenum)
73
- - [x-enumTitles](#x-enumtitles)
74
- - [x-format](#x-format)
75
- - [x-grid](#x-grid)
76
- - [x-hidden](#x-hidden)
77
- - [x-info](#x-info)
78
- - [x-inputAttributes](#x-inputattributes)
79
- - [x-messages](#x-messages)
80
- - [x-propertiesToggleContent](#x-propertiesToggleContent)
81
- - [x-showErrors](#x-showerrors)
82
- - [x-sortable](#x-sortable)
83
- - [x-startCollapsed](#x-startCollapsed)
84
- - [x-switcherTitle](#x-switchertitle)
85
- - [x-titleHidden](#x-titlehidden)
86
- - [x-titleIconClass](#x-titleiconclass)
87
- - [x-titleTemplate](#x-titleTemplate)
88
- - [License](#license)
89
- - [Resources](#resources)
21
+ 1. Your backend sends the JSON Schema to the client
22
+ 2. Jedison automatically renders a complete form based on the schema
23
+ 3. Users interact with the form while getting instant client-side validation
24
+ 4. Validated data gets submitted back to your server
25
+ 5. The same schema validates the data again server-side for security
90
26
 
91
- ## Key Features
27
+ ![Jedison use diagram](/mermaid-flow-transparent.svg)
92
28
 
93
- - Dependency free
94
- - JSON Schema Validation: Easily validate your JSON data using JSON schemas.
95
- - JSON Editing: Generate user-friendly forms for smooth JSON editing in the browser.
96
- - Dereferences JSON Schema <code>'$ref'</code> pointers.
97
- - CSS libraries Integration:
98
- - Bootstrap 3
99
- - Bootstrap 4
100
- - Bootstrap 5
101
- - Icon libraries Integration:
102
- - Glyphicons
103
- - Bootstrap icons
104
- - FontAwesome 3
105
- - FontAwesome 4
106
- - FontAwesome 5
107
- - FontAwesome 6
108
- - Plugin Editors:
109
- - Quill - powerful rich text editor
110
- - Flatpickr - lightweight and powerful datetime picker
111
- - Awesomplete - Ultra lightweight, customizable, simple autocomplete widget with zero dependencies
112
- - Jodit - WYSIWYG Editor
113
- - Raty - star Rating Plugin
114
- - IMask - vanilla javascript input mask
29
+ But Jedison is flexible enough to support other patterns too - you might use it for:
115
30
 
116
- ## Getting Started
31
+ - Standalone client-side forms without server validation
32
+ - Pure server-side JSON validation in your backend services
33
+ - Hybrid approaches where different parts of the schema are used in different contexts
117
34
 
118
35
  ## Install
119
36
 
120
- ### Package manager
37
+ ### Using ES Module
121
38
 
39
+ npm
122
40
  ```bash
123
41
  npm install jedison
124
42
  ```
125
43
 
44
+ yarn
126
45
  ```bash
127
46
  yarn add jedison
128
47
  ```
129
48
 
130
- ### CDN
131
-
132
- ```html
133
- <script src="https://cdn.jsdelivr.net/npm/jedison@0.1.1/dist/umd/jedison.umd.js"></script>
134
- ```
135
-
136
- ### As a Validator
137
-
138
- ```javascript
139
- const schema = {
140
- "type": "string"
141
- }
142
-
143
- const refParser = new Jedison.RefParser()
144
-
145
- const init = async () => {
146
- await refParser.dereference(schema)
147
-
148
- const jedison = new Jedison.Create({
149
- refParser: refParser,
150
- schema: schema
151
- })
152
- }
153
-
154
- init()
155
- ```
156
-
157
- ### As an Editor
158
-
159
49
  ```html
160
50
  <div id="jedison-container"></div>
161
- ```
162
-
163
- ```javascript
164
- const schema = {
165
- "type": "string"
166
- }
167
-
168
- const refParser = new Jedison.RefParser()
169
-
170
- const init = async () => {
171
- await refParser.dereference(schema)
172
-
173
- const jedison = new Jedison.Create({
174
- container: document.querySelector('#jedison-container'),
175
- theme: new Jedison.ThemeBootstrap3(),
176
- refParser: refParser,
177
- schema: schema
178
- })
179
- }
180
-
181
- init()
182
- ```
183
-
184
- ## Instance Methods
185
-
186
- ```javascript
187
- jedison.getValue() // returns the value of the editor
188
- jedison.setValue({name: "Marcus miller"}) // set the editor value
189
- jedison.getInstance('#/name') // gets the instance by json path
190
- jedison.showValidationErrors() // displays validation errors in the respective editors
191
- jedison.getErrors() // returns an array of validation error messages
192
- jedison.disable() // disables the editor
193
- jedison.enable() // enables the editor
194
- jedison.destroy() // destroys the editor
195
- ```
196
-
197
- ## Instance event listeners
198
-
199
- ```javascript
200
- // emitted when the jedison instance changes (whole json value/instance/editor)
201
- jedison.on('change', (initiator) => {
202
-
203
- })
204
-
205
- // emitted when an instance changes (parts of the value/instance/editor)
206
- jedison.on('instance-change', (instance, initiator) => {
207
-
208
- })
209
-
210
- // emitted when a new item to an array instance
211
- jedison.editor.on('item-add', (initiator, newInstance) => {
212
-
213
- })
214
-
215
- // emitted when an item is removed from an array instance
216
- jedison.editor.on('item-delete', (initiator) => {
217
51
 
218
- })
219
-
220
- // emitted when a new item is move up or down in an array instance
221
- jedison.editor.on('item-move', (initiator) => {
222
-
223
- })
224
- ```
225
-
226
- The argument `ìnitiator`can have one of the two values:
227
- - `"api"`: indicates that the change came from a call of a method like `setValue()` or from internal mechanism of this library.
228
- - `"user"`: indicates that the change came from a user interaction.
229
-
230
-
231
- ## RefParser
232
-
233
- A `RefParser` resolves `$ref` references in JSON Schemas by dereferencing then.
234
-
235
- ```json
236
- {
237
- "type": "object",
238
- "properties": {
239
- "user": {
240
- "$ref": "#/$defs/user"
241
- }
242
- },
243
- "$defs": {
244
- "user": {
245
- "type": "object",
246
- "properties": {
247
- "name": {
248
- "type": "string"
249
- },
250
- "email": {
251
- "type": "string",
252
- "format": "email"
52
+ <script type="module">
53
+ import Jedison from 'jedison'
54
+
55
+ const jedison = new Jedison.Create({
56
+ container: document.querySelector('#jedison-container'),
57
+ theme: new Jedison.Theme(),
58
+ schema: {
59
+ "title": "Person",
60
+ "type": "object",
61
+ "properties": {
62
+ "name": {
63
+ "type": "string",
64
+ "description": "The person's name."
65
+ },
66
+ "age": {
67
+ "description": "Age in years which must be equal to or greater than zero.",
68
+ "type": "integer",
69
+ "minimum": 0
70
+ }
71
+ }
253
72
  }
254
- }
255
- }
256
- }
257
- }
73
+ })
74
+ </script>
258
75
  ```
259
76
 
260
- translates to:
261
-
262
- ```json
263
- {
264
- "type": "object",
265
- "properties": {
266
- "user": {
267
- "type": "object",
268
- "properties": {
269
- "name": {
270
- "type": "string"
271
- },
272
- "email": {
273
- "type": "string",
274
- "format": "email"
275
- }
276
- }
277
- }
278
- }
279
- }
280
- ```
281
-
282
- ## Instance Options
283
-
284
- <table>
285
- <thead>
286
- <tr align="left">
287
- <th>Option</th>
288
- <th>Type</th>
289
- <th>Default</th>
290
- <th>Description</th>
291
- <th>As schema "x-" option</th>
292
- </tr>
293
- </thead>
294
- <tbody>
295
- <tr align="left">
296
- <td><code>container</code></td>
297
- <td><code>HTMLElement</code></td>
298
- <td><code>null</code></td>
299
- <td>The HTML element that will contain the generated form.</td>
300
- <td>no</td>
301
- </tr>
302
- <tr align="left">
303
- <td><code>iconLib</code></td>
304
- <td><code>string</code></td>
305
- <td><code>null</code></td>
306
- <td>
307
- Specifies the icon library to use for UI components. Valid options include:
308
- <ul>
309
- <li><code>'glyphicons'</code></li>
310
- <li><code>'bootstrap-icons'</code></li>
311
- <li><code>'fontawesome3'</code></li>
312
- <li><code>'fontawesome4'</code></li>
313
- <li><code>'fontawesome5'</code></li>
314
- <li><code>'fontawesome6'</code></li>
315
- </ul>
316
- </td>
317
- <td>no</td>
318
- </tr>
319
- <tr align="left">
320
- <td><code>theme</code></td>
321
- <td><code>Theme</code></td>
322
- <td><code>null</code></td>
323
- <td>
324
- An instance of <code>Theme</code> to apply to the UI. Valid options include:
325
- <ul>
326
- <li><code>new Jedison.Theme()</code></li>
327
- <li><code>new Jedison.ThemeBootstrap3()</code></li>
328
- <li><code>new Jedison.ThemeBootstrap4()</code></li>
329
- <li><code>new Jedison.ThemeBootstrap5()</code></li>
330
- </ul>
331
- </td>
332
- <td>no</td>
333
- </tr>
334
- <tr align="left">
335
- <td><code>refParser</code></td>
336
- <td><code>new Jedison.RefParser</code></td>
337
- <td><code>null</code></td>
338
- <td>An instance of <code>RefParser</code> to handle <code>'$ref'</code> keywords.</td>
339
- <td>no</td>
340
- </tr>
341
- <tr align="left">
342
- <td><code>translations</code></td>
343
- <td><code>object</code></td>
344
- <td><code>'{}'</code></td>
345
- <td>Used to add new translations or override the default ones.
346
- <pre>translations: {
347
- en: {
348
- errorEnum: 'LOL'
349
- }
350
- }</pre>
351
- </td>
352
- <td>no</td>
353
- </tr>
354
- <tr align="left">
355
- <td><code>parseMarkdown</code></td>
356
- <td><code>boolean</code></td>
357
- <td><code>false</code></td>
358
- <td>
359
- Transform <code>markdown</code> to <code>html</code> in annotations like <code>title</code> and <code>description</code> if marked.js is available as <code>window.marked</code>.
360
- </td>
361
- <td>no</td>
362
- </tr>
363
- <tr align="left">
364
- <td><code>purifyHtml</code></td>
365
- <td><code>boolean</code></td>
366
- <td><code>true</code></td>
367
- <td>
368
- Sanitizes <code>html</code> tags from annotations like if DOMPurify.js is available as <code>window.DOMPurify</code>.
369
- </td>
370
- <td>no</td>
371
- </tr>
372
- <tr align="left">
373
- <td><code>domPurifyOptions</code></td>
374
- <td><code>object</code></td>
375
- <td><code>{}</code></td>
376
- <td>
377
- DOMPurify options.
378
- </td>
379
- <td>no</td>
380
- </tr>
381
- <tr align="left">
382
- <td><code>schema</code></td>
383
- <td><code>object</code></td>
384
- <td><code>{}</code></td>
385
- <td>A JSON schema for the form.</td>
386
- <td>no</td>
387
- </tr>
388
- <tr align="left">
389
- <td><code>id</code></td>
390
- <td><code>string</code></td>
391
- <td><code>''</code></td>
392
- <td>Used to prefix <code>id</code> and <code>for</code> attributes</td>
393
- <td>no</td>
394
- </tr>
395
- <tr align="left">
396
- <td><code>language</code></td>
397
- <td><code>string</code></td>
398
- <td><code>'en'</code></td>
399
- <td>Set default language for error messages and UI texts</td>
400
- <td>no</td>
401
- </tr>
402
- <tr align="left">
403
- <td><code>data</code></td>
404
- <td><code>object</code></td>
405
- <td><code>undefined</code></td>
406
- <td>Initial data to populate the form.</td>
407
- <td>no</td>
408
- </tr>
409
- <tr align="left">
410
- <td><code>customEditors</code></td>
411
- <td><code>array</code></td>
412
- <td><code>[]</code></td>
413
- <td>An array of custom editor classes.</td>
414
- <td>no</td>
415
- </tr>
416
- <tr align="left">
417
- <td><code>hiddenInputAttributes</code></td>
418
- <td><code>object</code></td>
419
- <td><code>{}</code></td>
420
- <td>Attributes for hidden inputs in the form.</td>
421
- <td>no</td>
422
- </tr>
423
- <tr align="left">
424
- <td><code>settings</code></td>
425
- <td><code>object</code></td>
426
- <td><code>{}</code></td>
427
- <td>An object to store user data and functions. Useful for when there is the need to provide options to configure a plugin but the options can not be used in schemas because of JSON data limitations. Can be used in annotations when using templates</td>
428
- <td>no</td>
429
- </tr>
430
- <tr align="left">
431
- <td><code>btnContents</code></td>
432
- <td><code>boolean</code></td>
433
- <td><code>true</code></td>
434
- <td>If buttons texts should be displayed</td>
435
- <td>no</td>
436
- </tr>
437
- <tr align="left">
438
- <td><code>btnIcons</code></td>
439
- <td><code>boolean</code></td>
440
- <td><code>true</code></td>
441
- <td>If buttons icons should be displayed</td>
442
- <td>no</td>
443
- </tr>
444
- <tr align="left">
445
- <td><code>enforceEnum</code></td>
446
- <td><code>boolean</code></td>
447
- <td><code>true</code></td>
448
- <td>When <code>true</code> uses the first item in the enum as the default value</td>
449
- <td>yes</td>
450
- </tr>
451
- <tr align="left">
452
- <td><code>enforceRequired</code></td>
453
- <td><code>boolean</code></td>
454
- <td><code>true</code></td>
455
- <td>When <code>true</code> required properties are always displayed</td>
456
- <td>yes</td>
457
- </tr>
458
- <tr align="left">
459
- <td><code>enforceAdditionalProperties</code></td>
460
- <td><code>boolean</code></td>
461
- <td><code>true</code></td>
462
- <td>When <code>true</code> the editor removes all properties that are not listed in properties</td>
463
- <td>yes</td>
464
- </tr>
465
- <tr align="left">
466
- <td><code>switcherInput</code></td>
467
- <td><code>string</code></td>
468
- <td><code>'select'</code></td>
469
- <td>
470
- Sets the input type that will be used to witch between multiple editors
471
- <ul>
472
- <li><code>select</code></li>
473
- <li><code>radios</code></li>
474
- <li><code>radios-inline</code></li>
475
- </ul>
476
- </td>
477
- <td>yes</td>
478
- </tr>
479
- <tr align="left">
480
- <td><code>mergeAllOf</code></td>
481
- <td><code>boolean</code></td>
482
- <td><code>false</code></td>
483
- <td>
484
- Merge <code>allOf</code> subschemas into it's owner schema. <b>WARNING</b>, merging schemas can lead to unwanted overrides. Use at your own risk.
485
- </td>
486
- <td>yes</td>
487
- </tr>
488
- <tr align="left">
489
- <td><code>enablePropertiesToggle</code></td>
490
- <td><code>boolean</code></td>
491
- <td><code>false</code></td>
492
- <td>Enables a toggle to show/hide properties in the UI.</td>
493
- <td>yes</td>
494
- </tr>
495
- <tr align="left">
496
- <td><code>enableCollapseToggle</code></td>
497
- <td><code>boolean</code></td>
498
- <td><code>false</code></td>
499
- <td>Allows sections to be collapsible in the UI.</td>
500
- <td>yes</td>
501
- </tr>
502
- <tr align="left">
503
- <td><code>deactivateNonRequired</code></td>
504
- <td><code>boolean</code></td>
505
- <td><code>false</code></td>
506
- <td>Deactivates non-required properties.</td>
507
- <td>yes</td>
508
- </tr>
509
- <tr align="left">
510
- <td><code>showErrors</code></td>
511
- <td><code>string</code></td>
512
- <td><code>'change'</code></td>
513
- <td>
514
- Determines when to display validation errors. Options include:
515
- <ul>
516
- <li><code>'never'</code></li>
517
- <li><code>'change'</code></li>
518
- <li><code>'always'</code></li>
519
- </ul>
520
- </td>
521
- <td>yes</td>
522
- </tr>
523
- <tr align="left">
524
- <td><code>assertFormat</code></td>
525
- <td><code>boolean</code></td>
526
- <td><code>false</code></td>
527
- <td>Treats <code>'format'</code> as a validator rather than just an annotation.</td>
528
- <td>yes</td>
529
- </tr>
530
- <tr align="left">
531
- <td><code>enforceConst</code></td>
532
- <td><code>boolean</code></td>
533
- <td><code>false</code></td>
534
- <td>Enforces the <code>const</code> keyword value in editors.</td>
535
- <td>yes</td>
536
- </tr>
537
- <tr align="left">
538
- <td><code>arrayDelete</code></td>
539
- <td><code>boolean</code></td>
540
- <td><code>true</code></td>
541
- <td>If array delete buttons should be displayed</td>
542
- <td>yes</td>
543
- </tr>
544
- <tr align="left">
545
- <td><code>arrayMove</code></td>
546
- <td><code>boolean</code></td>
547
- <td><code>true</code></td>
548
- <td>If array move up and move down buttons should be displayed</td>
549
- <td>yes</td>
550
- </tr>
551
- <tr align="left">
552
- <td><code>arrayAdd</code></td>
553
- <td><code>boolean</code></td>
554
- <td><code>true</code></td>
555
- <td>If array add buttons should be displayed</td>
556
- <td>yes</td>
557
- </tr>
558
- </tbody>
559
- </table>
560
-
561
- ## Editors
562
-
563
- An editor is a UI that allows users to input data and finally edit the relative json instance.
564
- Editors can be as simple as a checkbox input filed for a boolean, or as complex as a wysiwyg rich text editor
565
- for a string representing html.
566
- The type of editor greatly depends on the type of json data that it's connected to and the keywords
567
- present in it's json schema.
568
-
569
- Virtually all editors can have the following features:
570
-
571
- - [x-assertFormat](#x-assertFormat)
572
- - [x-containerAttributes](#x-containerAttributes)
573
- - [x-enforceConst](#x-enforceconst)
574
- - [x-enforceEnum](#x-enforceEnum)
575
- - [x-hidden](#x-hidden)
576
- - [x-info](#x-info)
577
- - [x-inputAttributes](#x-inputattributes) (if any)
578
- - [x-messages](#x-messages)
579
- - [x-showErrors](#x-showerrors)
580
- - [x-titleHidden](#x-titlehidden)
581
- - [x-titleIconClass](#x-titleiconclass)
582
-
583
- ```json
584
- {
585
- "type": "string",
586
- "title": "label text for this editor",
587
- "description": "description text for this editor",
588
- "x-info": {
589
- "variant": "modal",
590
- "title": "<h4>Info Button title</h4>",
591
- "content": "<p>Info button content</p>"
592
- },
593
- "x-inputAttributes": {
594
- "placeholder": "placeholder text"
595
- }
596
- }
597
- ```
598
-
599
- ### Array editors
600
-
601
- Options:
602
-
603
- - [x-arrayAdd](#x-arrayAdd)
604
- - [x-arrayAddContent](#x-arrayAddContent)
605
- - [x-arrayDelete](#x-arrayDelete)
606
- - [x-arrayDeleteContent](#x-arrayDeleteContent)
607
- - [x-arrayDragContent](#x-arrayDragContent)
608
- - [x-arrayMove](#x-arrayMove)
609
- - [x-arrayMoveDownContent](#x-arrayMoveDownContent)
610
- - [x-arrayMoveUpContent](#x-arrayMoveUpContent)
611
- - [x-collapseToggleContent](#x-collapseToggleContent)
612
- - [x-enableCollapseToggle](#x-enableCollapseToggle)
613
- - [x-sortable](#x-sortable)
614
- - [x-startCollapsed](#x-startCollapsed)
615
- - [x-titleTemplate](#x-titleTemplate)
616
-
617
- #### Array list
618
-
619
- A fieldset that can contain list of editors. Each child editor correspond to an items in the array.
620
- Child editors are placed from top to bottom.
621
-
622
- ```json
623
- {
624
- "type": "array",
625
- "title": "Array",
626
- "description": "Arrays are used for ordered elements. In JSON, each element in an array may be of a different type.",
627
- "items": {
628
- "title": "I am an array item editor",
629
- "type": "string"
630
- }
631
- }
632
- ```
633
-
634
- #### Array checkboxes
635
-
636
- A fieldset containing a list of enumerated editors. Each editor is represented by a checkboxes.
637
- Works only if the items are of type `string`, `number` or `integer`.
638
-
639
- ```json
640
- {
641
- "title": "Array",
642
- "description": "Array of unique values wich item types can be string, number or integer",
643
- "type": "array",
644
- "uniqueItems": true,
645
- "items": {
646
- "enum": [
647
- "value1",
648
- "value2"
649
- ]
650
- }
651
- }
652
- ```
653
-
654
- checkbox inline variant
655
-
656
- ```json
657
- {
658
- "x-format": "checkboxes-inline",
659
- "title": "Array",
660
- "description": "Array of unique values wich item types can be string, number or integer",
661
- "type": "array",
662
- "uniqueItems": true,
663
- "items": {
664
- "type": "string",
665
- "enum": [
666
- "value1",
667
- "value2"
668
- ]
669
- }
670
- }
671
- ```
672
-
673
- #### Array choices
674
-
675
- A fieldset containing a list of enumerated editors. Each editor is represented by an item in the choices input.
676
- Works only if the items are of type `string`, `number` or `integer`.
677
- Choices.js musst be installed and available as `window.Choices` for this to work.
678
-
679
- ```json
680
- {
681
- "x-format": "choices",
682
- "title": "Choices",
683
- "description": "A vanilla JS customisable select box/text input plugin.",
684
- "type": "array",
685
- "uniqueItems": true,
686
- "items": {
687
- "type": "string",
688
- "enum": [
689
- "US",
690
- "CA",
691
- "GB",
692
- "FR",
693
- "DE",
694
- "IT",
695
- "IN",
696
- "JP",
697
- "BR",
698
- "AU"
699
- ],
700
- "x-enumTitles": [
701
- "United States (US)",
702
- "Canada (CA)",
703
- "United Kingdom (GB)",
704
- "France (FR)",
705
- "Germany (DE)",
706
- "Italy (IT)",
707
- "India (IN)",
708
- "Japan (JP)",
709
- "Brazil (BR)",
710
- "Australia (AU)"
711
- ]
712
- },
713
- "default": [
714
- "US"
715
- ],
716
- "minItems": 1
717
- }
718
- ```
719
-
720
- #### Array nav
721
-
722
- A fieldset containing a list of enumerated editors. Each editor is represented by a checkboxes.
723
- Works only if the items are of type `string`, `number` or `integer`.
724
-
725
- options:
726
-
727
- - `titleTemplate` is used to dynamically generate the nav items text. The parameters available are:
728
- - `{{ i0 }}` is the index of the item starting by 0.
729
- - `{{ i1 }}` is the index of the item starting by 1. More useful for end users.
730
- - `{{ value }}` The value of the items.
731
-
732
- With vertical nav
733
-
734
- ```json
735
- {
736
- "x-format": "nav-vertical",
737
- "x-titleTemplate": "{{ i1 }} {{ value.name }}",
738
- "type": "array",
739
- "title": "People",
740
- "items": {
741
- "type": "object",
742
- "title": "Person",
743
- "properties": {
744
- "name": {
745
- "title": "Name",
746
- "type": "string"
747
- }
748
- }
749
- },
750
- "default": [
751
- {
752
- "name": "Albert"
753
- }
754
- ]
755
- }
756
- ```
757
-
758
- With horizontal nav
759
-
760
- ```json
761
- {
762
- "x-format": "nav-horizontal",
763
- "x-titleTemplate": "{{ i1 }} {{ value.name }}",
764
- "type": "array",
765
- "title": "People",
766
- "items": {
767
- "type": "object",
768
- "title": "Person",
769
- "properties": {
770
- "name": {
771
- "title": "Name",
772
- "type": "string"
773
- }
774
- }
775
- },
776
- "default": [
777
- {
778
- "name": "Albert"
779
- }
780
- ]
781
- }
782
- ```
783
-
784
- #### Array table
785
-
786
- A table where each item editor is rendered in a new table row.
787
-
788
- ```json
789
- {
790
- "x-format": "table",
791
- "title": "users",
792
- "type": "array",
793
- "items": {
794
- "type": "object",
795
- "title": "Person",
796
- "description": "User",
797
- "properties": {
798
- "name": {
799
- "type": "string",
800
- "title": "Name"
801
- }
802
- }
803
- },
804
- "default": [
805
- {
806
- "name": "Albert"
807
- },
808
- {
809
- "name": "Betti"
810
- }
811
- ]
812
- }
813
- ```
814
-
815
- ### Boolean editors
816
-
817
- #### Boolean checkbox
818
-
819
- Renders a type checkbox input
820
-
821
- ```json
822
- {
823
- "x-format": "checkbox",
824
- "type": "boolean",
825
- "title": "Boolean"
826
- }
827
- ```
828
-
829
- #### Boolean radios
830
-
831
- Renders two type radio inputs. The radio labels can be customized with the
832
- `enumTitles` option.
833
-
834
- ```json
835
- {
836
- "x-format": "radios",
837
- "type": "boolean",
838
- "title": "Boolean",
839
- "x-enumTitles": [
840
- "Yes",
841
- "No"
842
- ]
843
- }
844
- ```
845
-
846
- Inline variant
847
-
848
- ```json
849
- {
850
- "x-format": "radios-inline",
851
- "type": "boolean",
852
- "title": "Boolean",
853
- "x-enumTitles": [
854
- "Yes",
855
- "No"
856
- ]
857
- }
858
- ```
859
-
860
- #### Boolean select
861
-
862
- Renders type select input with 2 options. The options labels can be customized with the
863
- `enumTitles` option.
864
-
865
- ```json
866
- {
867
- "x-format": "select",
868
- "type": "boolean",
869
- "title": "Boolean",
870
- "x-enumTitles": [
871
- "Yes",
872
- "No"
873
- ]
874
- }
875
- ```
876
-
877
- ### Number editors
878
-
879
- #### Number input
880
-
881
- Renders type number input. Handles `number`and `integer` types.
882
-
883
- ```json
884
- {
885
- "type": "number",
886
- "title": "Number"
887
- }
888
- ```
889
-
890
- #### Number radios
891
-
892
- Renders as many radio type inputs as values in the `enum` constraint. The radio labels can be customized with the
893
- `enumTitles` option. Handles `number`and `integer` types.
894
-
895
- ```json
896
- {
897
- "x-format": "radios",
898
- "type": "number",
899
- "title": "Quantity",
900
- "enum": [
901
- 0,
902
- 1,
903
- 2
904
- ],
905
- "x-enumTitles": [
906
- "None",
907
- "One",
908
- "A pair"
909
- ]
910
- }
911
- ```
912
-
913
- Inline variant
914
-
915
- ```json
916
- {
917
- "x-format": "radios-inline",
918
- "type": "number",
919
- "title": "Quantity",
920
- "enum": [
921
- 0,
922
- 1,
923
- 2
924
- ],
925
- "x-enumTitles": [
926
- "None",
927
- "One",
928
- "A pair"
929
- ]
930
- }
931
- ```
932
-
933
- #### Number select
934
-
935
- Renders as many radio type inputs as values in the `enum` constraint. The options labels can be customized with the
936
- `enumTitles` option. Handles `number`and `integer` types.
937
-
938
- ```json
939
- {
940
- "type": "number",
941
- "title": "Quantity",
942
- "enum": [
943
- 0,
944
- 1,
945
- 2
946
- ],
947
- "x-enumTitles": [
948
- "None",
949
- "One",
950
- "A pair"
951
- ]
952
- }
953
- ```
954
-
955
- #### Number Raty
956
-
957
- Renders a star rating input using Raty.js if installed and available as `window.Raty`.
958
-
959
- ```json
960
- {
961
- "title": "Raty",
962
- "type": "number",
963
- "description": "Raty - A Star Rating Plugin",
964
- "default": 3,
965
- "minimum": 0.5,
966
- "x-raty": {
967
- "half": true,
968
- "starType": "i"
969
- }
970
- }
971
- ```
972
-
973
- ### Object editors
974
-
975
- options:
976
-
977
- - [x-addPropertyContent](#x-addPropertyContent)
978
- - [x-collapseToggleContent](#x-collapseToggleContent)
979
- - [x-deactivateNonRequired](#x-deactivateNonRequired)
980
- - [x-enableCollapseToggle](#x-enableCollapseToggle)
981
- - [x-propertiesToggleContent](#x-propertiesToggleContent)
982
- - [x-startCollapsed](#x-startCollapsed)
983
- - [x-titleTemplate](#x-titleTemplate)
984
-
985
- #### Object
986
-
987
- Renders a fieldset that will contain it properties editors.
988
- The fieldset can be collapsed or expanded.
989
-
990
- ```json
991
- {
992
- "type": "object",
993
- "title": "Login",
994
- "properties": {
995
- "email": {
996
- "title": "E-Mail",
997
- "type": "string",
998
- "format": "email"
999
- },
1000
- "password": {
1001
- "title": "Password",
1002
- "type": "string",
1003
- "minLength": 8
1004
- }
1005
- }
1006
- }
1007
- ```
1008
-
1009
- #### Object grid
1010
-
1011
- Renders a fieldset that will contain it properties editors and use a grid system to position
1012
- its property editors. The fieldset can be collapsed or expanded.
1013
- Property editors can have more options:
1014
-
1015
- - `columns`: How many columns should the editor occupy.
1016
- - `offset`: How many columns should the editor be offset.
1017
- - `newRow`: Whether the editor should be put in a new row.
1018
-
1019
- ```json
1020
- {
1021
- "x-format": "grid",
1022
- "type": "object",
1023
- "title": "Login",
1024
- "properties": {
1025
- "email": {
1026
- "title": "E-Mail",
1027
- "type": "string",
1028
- "format": "email",
1029
- "x-grid": {
1030
- "columns": 6
1031
- }
1032
- },
1033
- "password": {
1034
- "title": "Password",
1035
- "type": "string",
1036
- "minLength": 8,
1037
- "x-grid": {
1038
- "columns": 6
1039
- }
1040
- }
1041
- }
1042
- }
1043
- ```
1044
-
1045
- #### Object nav
1046
-
1047
- Renders a fieldset that will contain it properties editors.
1048
- The fieldset can be collapsed or expanded.
1049
-
1050
- With vertical nav
1051
-
1052
- ```json
1053
- {
1054
- "x-format": "nav-vertical",
1055
- "type": "object",
1056
- "title": "All Editors",
1057
- "properties": {
1058
- "personA": {
1059
- "title": "Person A",
1060
- "type": "object",
1061
- "properties": {
1062
- "name": {
1063
- "type": "string"
1064
- },
1065
- "age": {
1066
- "type": "integer",
1067
- "minimum": 0
1068
- }
1069
- }
1070
- },
1071
- "personB": {
1072
- "title": "Person B",
1073
- "type": "object",
1074
- "properties": {
1075
- "name": {
1076
- "type": "string"
1077
- },
1078
- "age": {
1079
- "type": "integer",
1080
- "minimum": 0
1081
- }
1082
- }
1083
- }
1084
- }
1085
- }
1086
- ```
1087
-
1088
- With horizontal nav
1089
-
1090
- ```json
1091
- {
1092
- "x-format": "nav-horizontal",
1093
- "type": "object",
1094
- "title": "All Editors",
1095
- "properties": {
1096
- "personA": {
1097
- "title": "Person A",
1098
- "type": "object",
1099
- "properties": {
1100
- "name": {
1101
- "type": "string"
1102
- },
1103
- "age": {
1104
- "type": "integer",
1105
- "minimum": 0
1106
- }
1107
- }
1108
- },
1109
- "personB": {
1110
- "title": "Person B",
1111
- "type": "object",
1112
- "properties": {
1113
- "name": {
1114
- "type": "string"
1115
- },
1116
- "age": {
1117
- "type": "integer",
1118
- "minimum": 0
1119
- }
1120
- }
1121
- }
1122
- }
1123
- }
1124
- ```
1125
-
1126
- ### String editors
1127
-
1128
- #### String input
1129
-
1130
- Renders type text input.
1131
-
1132
- ```json
1133
- {
1134
- "type": "string",
1135
- "title": "String"
1136
- }
1137
- ```
1138
-
1139
- #### String radios
1140
-
1141
- Renders as many radio type inputs as values in the `enum` constraint. The radio labels can be customized with the
1142
- `enumTitles` option.
1143
-
1144
- ```json
1145
- {
1146
- "x-format": "radios",
1147
- "type": "string",
1148
- "title": "String radios",
1149
- "enum": [
1150
- "albert",
1151
- "betti",
1152
- "carl"
1153
- ],
1154
- "x-enumTitles": [
1155
- "Albert",
1156
- "Betti",
1157
- "Carl"
1158
- ]
1159
- }
1160
- ```
1161
-
1162
- Inline variant
1163
-
1164
- ```json
1165
- {
1166
- "x-format": "radios-inline",
1167
- "type": "string",
1168
- "title": "String radios",
1169
- "enum": [
1170
- "albert",
1171
- "betti",
1172
- "carl"
1173
- ],
1174
- "x-enumTitles": [
1175
- "Albert",
1176
- "Betti",
1177
- "Carl"
1178
- ]
1179
- }
1180
- ```
1181
-
1182
- #### String select
1183
-
1184
- Renders as many radio type inputs as values in the `enum` constraint. The options labels can be customized with the
1185
- `enumTitles` option.
1186
-
1187
- ```json
1188
- {
1189
- "type": "string",
1190
- "title": "String select",
1191
- "enum": [
1192
- "albert",
1193
- "betti",
1194
- "carl"
1195
- ],
1196
- "x-enumTitles": [
1197
- "Albert",
1198
- "Betti",
1199
- "Carl"
1200
- ]
1201
- }
1202
- ```
1203
-
1204
- #### String textarea
1205
-
1206
- Renders textarea input.
1207
-
1208
- ```json
1209
- {
1210
- "x-format": "textarea",
1211
- "type": "string",
1212
- "title": "String"
1213
- }
1214
- ```
1215
-
1216
- #### String awesomplete
1217
-
1218
- Renders a autocomplete featured text input using Awesomplete.js if installed and available as `window.Awesomplete`.
77
+ ### Using fromCDN
1219
78
 
1220
- ```json
1221
- {
1222
- "title": "Awesomplete",
1223
- "type": "string",
1224
- "description": "Awesomplete is an ultra lightweight, customizable, simple autocomplete widget with zero dependencies, built with modern standards for modern browsers.",
1225
- "default": "Awesomplete default",
1226
- "minLength": 1,
1227
- "x-awesomplete": {
1228
- "list": [
1229
- "JavaScript",
1230
- "Java",
1231
- "Python",
1232
- "Ruby",
1233
- "C++",
1234
- "C#",
1235
- "PHP",
1236
- "Swift",
1237
- "Go",
1238
- "Kotlin"
1239
- ],
1240
- "minChars": 1,
1241
- "maxItems": 5,
1242
- "autoFirst": true
1243
- }
1244
- }
1245
- ```
1246
-
1247
- #### String flatpickr
1248
-
1249
- Renders a datetime picker using flatpickr.js if installed and available as `window.flatpickr`.
1250
-
1251
- ```json
1252
- {
1253
- "title": "Flatpickr",
1254
- "type": "string",
1255
- "description": "Flatpickr is a lightweight and powerful datetime picker.",
1256
- "default": "2024-08-27",
1257
- "minLength": 3,
1258
- "x-flatpickr": {}
1259
- }
1260
- ```
1261
-
1262
- #### String imask
1263
-
1264
- Renders a masked text input using IMask.js if installed and available as `window.IMask`.
1265
-
1266
- ```json
1267
- {
1268
- "title": "IBAN",
1269
- "type": "string",
1270
- "x-imask": {
1271
- "mask": "DE00 0000 0000 0000 0000 00",
1272
- "lazy": false
1273
- }
1274
- }
1275
- ```
1276
-
1277
- This example feature configuration through the Jedison instance `settings` option due to the impossibility
1278
- of configuring the plugin with just JSON data. note that for custom options the prefix `x-` is still being used.
1279
-
1280
- ```json
1281
- {
1282
- "title": "Date",
1283
- "type": "string",
1284
- "x-imask": {
1285
- "x-settings": "imaskDate"
1286
- }
1287
- }
1288
- ```
1289
-
1290
- ```javascript
1291
- const options = {
1292
- settings: {
1293
- imaskDate: {
1294
- mask: Date,
1295
- min: new Date(1990, 0, 1),
1296
- max: new Date(2020, 0, 1),
1297
- lazy: false
1298
- }
1299
- }
1300
- }
1301
- ```
1302
-
1303
- #### String Jodit
1304
-
1305
- Renders a WYSIWYG editor using Jodit.js if installed and available as `window.Jodit`.
1306
-
1307
- ```json
1308
- {
1309
- "title": "Jodit",
1310
- "type": "string",
1311
- "description": "Jodit - Best WYSIWYG Editor for You.",
1312
- "default": "Jodit default",
1313
- "minLength": 20,
1314
- "x-jodit": {}
1315
- }
1316
- ```
1317
-
1318
- #### String Quill
1319
-
1320
- Renders a WYSIWYG editor using Quill.js if installed and available as `window.Quill`.
1321
-
1322
- ```json
1323
- {
1324
- "title": "Quill",
1325
- "type": "string",
1326
- "description": "Quill is a modern WYSIWYG editor built for compatibility and extensibility.",
1327
- "default": "Quill default",
1328
- "minLength": 3,
1329
- "x-quill": {
1330
- "theme": "snow"
1331
- }
1332
- }
1333
- ```
1334
-
1335
- ### Null editors
1336
-
1337
- #### Null
1338
-
1339
- No input is rendered.
1340
-
1341
- ```json
1342
- {
1343
- "type": "null",
1344
- "title": "Null"
1345
- }
1346
- ```
1347
-
1348
- ## Language and Translations
1349
-
1350
- The default language for UI and error messages is `en` (english). The language can be set to any of
1351
- the supported languages in the instance options.
1352
-
1353
- This will set german as the default language:
1354
-
1355
- ```javascript
1356
- const jedison = new Jedison.Create({
1357
- language: 'de'
1358
- })
1359
- ```
1360
-
1361
- Currently, the supported languages are `en` (english), `de` (german), `it` (italian) and `es` (spanish).
1362
- New languages can be added to the `translations` option. To use them the `language` options
1363
- should be set to the language specified.
1364
-
1365
- The default translation can be overridden in the instance options as well.
1366
-
1367
- ```javascript
1368
- const jedison = new Jedison.Create({
1369
- language: 'de',
1370
- translations: {
1371
- de: {
1372
- errorAdditionalProperties: 'Hat die zusätzliche Eigenschaft "{{ property }}", aber keine zusätzlichen Eigenschaften sind erlaubt.',
1373
- errorAnyOf: 'Muss mindestens einem der bereitgestellten Schemata entsprechen.',
1374
- errorConst: 'Muss den Wert {{ const }} haben.',
1375
- errorContains: 'Muss mindestens ein Element enthalten, das dem bereitgestellten Schema entspricht.',
1376
- errorDependentRequired: 'Muss die erforderlichen Eigenschaften haben: {{ dependentRequired }}.',
1377
- errorEnum: 'Muss einer der aufgeführten Werte sein: {{ enum }}.',
1378
- errorExclusiveMaximum: 'Muss kleiner als {{ exclusiveMaximum }} sein.',
1379
- errorExclusiveMinimum: 'Muss größer als {{ exclusiveMinimum }} sein.',
1380
- errorFormat: 'Muss ein gültiges {{ format }} sein.',
1381
- errorItems: 'Muss Elemente enthalten, die dem bereitgestellten Schema entsprechen.',
1382
- errorMaximum: 'Muss höchstens {{ maximum }} sein.',
1383
- errorMaxItems: 'Darf höchstens {{ maxItems }} Elemente enthalten.',
1384
- errorMaxLength: 'Darf höchstens {{ maxLength }} Zeichen lang sein.',
1385
- errorMaxProperties: 'Darf höchstens {{ maxProperties }} Eigenschaften haben.',
1386
- errorMaxContains: 'Darf höchstens {{ maxContains }} Elemente enthalten, die dem bereitgestellten Schema entsprechen. Aktuell enthält es {{ counter }}.',
1387
- errorMinContains: 'Muss mindestens {{ minContains }} Elemente enthalten, die dem bereitgestellten Schema entsprechen. Aktuell enthält es {{ counter }}.',
1388
- errorMinimum: 'Muss mindestens {{ minimum }} sein.',
1389
- errorMinItems: 'Muss mindestens {{ minItems }} Elemente enthalten.',
1390
- errorMinLength: 'Muss mindestens {{ minLength }} Zeichen lang sein.',
1391
- errorMinProperties: 'Muss mindestens {{ minProperties }} Eigenschaften haben.',
1392
- errorMultipleOf: 'Muss ein Vielfaches von {{ multipleOf }} sein.',
1393
- errorNot: 'Darf nicht dem bereitgestellten Schema entsprechen.',
1394
- errorOneOf: 'Muss genau einem der bereitgestellten Schemata entsprechen. Derzeit entspricht es {{ counter }} der Schemata.',
1395
- errorPattern: 'Muss dem Muster "{{ pattern }}" entsprechen.',
1396
- errorPrefixItems: 'Element {{ index }} entspricht nicht der Validierung.',
1397
- errorPropertyNames: 'Der Eigenschaftsname "{{ propertyName }}" entspricht nicht der Validierung.',
1398
- errorProperties: 'Die folgenden Eigenschaften entsprechen nicht ihren Schemata: {{ properties }}',
1399
- errorRequired: 'Muss die erforderlichen Eigenschaften haben: {{ required }}.',
1400
- errorType: 'Muss vom Typ {{ type }} sein.',
1401
- errorUnevaluatedProperties: 'Hat eine ungültige nicht bewertete Eigenschaft "{{ property }}"',
1402
- errorUniqueItems: 'Muss eindeutige Elemente haben.',
1403
- arrayDelete: 'Element löschen',
1404
- arrayMoveUp: 'Nach oben verschieben',
1405
- arrayMoveDown: 'Nach unten verschieben',
1406
- arrayDrag: 'Ziehen',
1407
- arrayAdd: 'Element hinzufügen',
1408
- arrayConfirmDelete: 'Möchten Sie dieses Element wirklich löschen?',
1409
- objectAddProperty: 'Eigenschaft hinzufügen',
1410
- objectPropertyAdded: 'Feld wurde dem Formular hinzugefügt',
1411
- objectPropertyRemoved: 'Feld wurde aus dem Formular entfernt',
1412
- propertiesToggle: 'Eigenschaften',
1413
- collapseToggle: 'Einklappen'
1414
- }
1415
- }
1416
- })
1417
- ```
1418
-
1419
- The text between brackets like `{{ minimum }}` or `{{ minLength }}` are templates.
1420
- This templates will be replaced dynamically with values specified in constraints.
1421
-
1422
- The error message for the following schema will be "Muss mindestens `3` Zeichen lang sein."
1423
- because of the `minLength: 3`.
1424
-
1425
- ```json
1426
- {
1427
- "title": "Email",
1428
- "format": "email",
1429
- "type": "string",
1430
- "minLength": 3
1431
- }
1432
- ```
1433
-
1434
- ## Annotations
1435
-
1436
- ### markdown
1437
- In schemas, `markdown` can be used in annotation to generate `html` content. This works only if
1438
- marked.js is installed and available as `window.marked`.
1439
-
1440
- ```json
1441
- {
1442
- "type": "object",
1443
- "title": "markdown annotations",
1444
- "properties": {
1445
- "name": {
1446
- "title": "**markdown to html title**",
1447
- "type": "string"
1448
- }
1449
- }
1450
- }
1451
- ```
1452
-
1453
- ## Schema options
1454
-
1455
- The `x-` or `x-options` [custom annotation](https://json-schema.org/blog/posts/custom-annotations-will-continue#what's-the-solution)
1456
- can be used in JSON Schemas to changes how instances and editors behave.
1457
- Schema `x-` options override global options.
1458
-
1459
- ```json
1460
- {
1461
- "title": "Message",
1462
- "type": "string",
1463
- "x-showErrors": "always"
1464
- }
1465
- ```
1466
-
1467
- Some options depend on other options to be set. In the example the option `"enumTitles"`
1468
- depends on the option `"enum"`.
1469
-
1470
- ```json
1471
- {
1472
- "title": "Type",
1473
- "type": "string",
1474
- "enum": [
1475
- "#000000",
1476
- "#ffffff"
1477
- ],
1478
- "x-enumTitles": [
1479
- "Black",
1480
- "White"
1481
- ]
1482
- }
1483
- ```
1484
-
1485
- ### `x-addPropertyContent`
1486
-
1487
- - Type: `boolean`
1488
- - Default: -
1489
- - Description: Text content for "add property" buttons.
1490
-
1491
- ### `x-arrayAdd`
1492
-
1493
- - Type: `boolean`
1494
- - Default: `true`
1495
- - Description: If array add buttons should be displayed.
1496
-
1497
- ### `x-arrayAddContent`
1498
-
1499
- - Type: `boolean`
1500
- - Default: -
1501
- - Description: Text content for array "add" buttons.
1502
-
1503
- ### `x-arrayDelete`
1504
-
1505
- - Type: `boolean`
1506
- - Default: `true`
1507
- - Description: If array delete buttons should be displayed.
1508
-
1509
- ### `x-arrayDeleteContent`
1510
-
1511
- - Type: `boolean`
1512
- - Default: -
1513
- - Description: Text content for array "delete" buttons.
1514
-
1515
- ### `x-arrayDragContent`,
1516
-
1517
- - Type: `boolean`
1518
- - Default: -
1519
- - Description: Text content for array "drag" buttons.
1520
-
1521
- ### `x-arrayMove`
1522
-
1523
- - Type: `boolean`
1524
- - Default: `true`
1525
- - Description: If array move up and move down buttons should be displayed.
1526
-
1527
- ### `x-arrayMoveDownContent`
1528
-
1529
- - Type: `boolean`
1530
- - Default: -
1531
- - Description: Text content for array "move down" buttons.
1532
-
1533
- ### `x-arrayMoveUpContent`
1534
-
1535
- - Type: `boolean`
1536
- - Default: -
1537
- - Description: Text content for array "move up" buttons.
1538
-
1539
- ### `x-assertFormat`
1540
-
1541
- - Type: `boolean`
1542
- - Default: `"false"`
1543
- - Options: `"never"`, `"change"`, `"always"`
1544
- - Description: Treats `"format"` as a validator rather than just an annotation.
1545
-
1546
- Treat `"format": "email"` as a constraint keyword instead of an annotation.
1547
-
1548
- ```json
1549
- {
1550
- "title": "Message",
1551
- "type": "string",
1552
- "format": "email",
1553
- "x-assertFormat": true
1554
- }
1555
- ```
1556
-
1557
- ### `x-collapseToggleContent`
1558
-
1559
- - Type: `boolean`
1560
- - Default: -
1561
- - Description: Text content for "collapse" buttons.
1562
-
1563
- ### `x-containerAttributes`
1564
-
1565
- - Type: `object`
1566
- - Description: Editors container HTML attributes can be set using the `x-containerAttributes` option. Attributes such as `class` or `data-*` will be applied to the container element.
1567
-
1568
- ```json
1569
- {
1570
- "title": "`x-containerAttributes`",
1571
- "type": "object",
1572
- "description": "Editors container HTML attributes can be set using the `x-containerAttributes` option. Attributes such as `class` or `data-*` will be applied to the container element.",
1573
- "x-containerAttributes": {
1574
- "class": "a-class another-class",
1575
- "data-custom": "custom-data"
1576
- }
1577
- }
1578
- ```
1579
-
1580
- ### `x-deactivateNonRequired`
1581
-
1582
- - Type: `boolean`
1583
- - Description: Whether the editor should deactivate (hide) or activate (show) non required properties. Works on only with `object` type editors.
1584
-
1585
- Only the property `name` is active
1586
-
1587
- ```json
1588
- {
1589
- "title": "Person",
1590
- "type": "object",
1591
- "x-deactivateNonRequired": true,
1592
- "required": [
1593
- "name"
1594
- ],
1595
- "properties": {
1596
- "name": {
1597
- "type": "string",
1598
- "title": "Name"
1599
- },
1600
- "age": {
1601
- "type": "integer",
1602
- "title": "Age"
1603
- }
1604
- }
1605
- }
1606
- ```
1607
-
1608
- ### `x-enableCollapseToggle`
1609
-
1610
- - Type: `boolean`
1611
- - Description: Display a collapse button used to collapse or expand editors that support collapse like `object` and `arrays`
1612
-
1613
- ### `x-enforceConst`
1614
-
1615
- - Type: `boolean`
1616
- - Default: `true`
1617
- - Description: Value will remain whatever is defined in schema `"const"`.
1618
-
1619
- Default value for this editor will be `"ff0000"`.
1620
-
1621
- ```json
1622
- {
1623
- "title": "Color",
1624
- "type": "string",
1625
- "const": "ff0000",
1626
- "x-enforceConst": true
1627
- }
1628
- ```
1629
-
1630
- ### `x-enforceEnum`
1631
-
1632
- - Type: `boolean`
1633
- - Default: `true`
1634
- - Description: Whether the editor initial value will be the first item in the `"enum"`.
1635
-
1636
- Default value for this editor will be `""`.
1637
-
1638
- ```json
1639
- {
1640
- "title": "Color",
1641
- "type": "string",
1642
- "enum": [
1643
- "ff0000",
1644
- "00ff00",
1645
- "0000ff"
1646
- ],
1647
- "x-enforceEnum": false
1648
- }
1649
- ```
1650
-
1651
- Default value for this editor will be `"ff0000"`.
1652
-
1653
- ```json
1654
- {
1655
- "title": "Color",
1656
- "type": "string",
1657
- "enum": [
1658
- "ff0000",
1659
- "00ff00",
1660
- "0000ff"
1661
- ],
1662
- "x-enforceEnum": true
1663
- }
1664
- ```
1665
-
1666
- ### `x-enumTitles`
1667
-
1668
- - Type: `string[]`
1669
- - Description: Used to display user-friendly labels in the editor instead of those listen in `"enum"`.
1670
-
1671
- Display color names instead of hex codes.
1672
-
1673
- ```json
1674
- {
1675
- "title": "Color",
1676
- "type": "string",
1677
- "enum": [
1678
- "ff0000",
1679
- "00ff00",
1680
- "0000ff"
1681
- ],
1682
- "x-enumTitles": [
1683
- "Red",
1684
- "Green",
1685
- "Blue"
1686
- ]
1687
- }
1688
- ```
1689
-
1690
- ### `x-format`
1691
-
1692
- - Type: `string`
1693
- - Description: Determines which editor UI will be used to edit the json einstance.
1694
-
1695
- Use radios editor to display color names instead of hex codes.
1696
-
1697
- ```json
1698
- {
1699
- "title": "Color",
1700
- "type": "string",
1701
- "enum": [
1702
- "Red",
1703
- "Green",
1704
- "Blue"
1705
- ],
1706
- "x-format": "radios"
1707
- }
1708
- ```
1709
-
1710
- ### `x-grid`
1711
-
1712
- - Type: `object`
1713
- - Description: A configuration object to determine the position of the property editor in the parent's grid.
1714
- - Options:
1715
- - `columns`: How many columns should the editor occupy.
1716
- - `offset`: How many columns should the editor be offsetted.
1717
- - `newRow`: Whether the editor should be put in a new row.
1718
-
1719
- ### `x-hidden`
1720
-
1721
- - Type: `boolean`
1722
- - Description: Editors can be hidden using the `x-hidden` option. When set to `true`, the editor is hidden.
1723
-
1724
- ### `x-info`
1725
-
1726
- - Type: `object`
1727
- - Description: Used to display extra information. If `markdown` is used to generate `html` content, it can be sanitized by DOMPurify is available, otherwise only the textContent will be displayed without any HTML tags.
1728
- - Options:
1729
- - `variant`: `"modal"`
1730
- - `title`: Plain text or `markdown`.
1731
- - `content`: Plain text or `markdown`.
1732
-
1733
- Displays an info button right after the title, that opens a modal with title and content.
1734
-
1735
- ```json
1736
- {
1737
- "title": "Message",
1738
- "type": "string",
1739
- "x-info": {
1740
- "variant": "modal",
1741
- "title": "### Info Button title",
1742
- "content": "Info button content"
1743
- }
1744
- }
1745
- ```
1746
-
1747
- ### `x-inputAttributes`
1748
-
1749
- - Type: `object`
1750
- - Description: Used to set attributes for the editor input.
1751
-
1752
- Add `placeholder` attribute to textarea.
1753
-
1754
- ```json
1755
- {
1756
- "title": "Message",
1757
- "type": "string",
1758
- "x-format": "textarea",
1759
- "x-inputAttributes": {
1760
- "placeholder": "Your message here..."
1761
- }
1762
- }
1763
- ```
1764
-
1765
- ### `x-messages`
1766
-
1767
- - Type: `object` | `string[]`
1768
- - Description: Validation error messages can be customized using the `x-messages` option in the schema.
1769
-
1770
- Validation error messages can be customized using the `x-messages` option in the schema. When defined as an object, messages can be applied by constraint (e.g., `minLength`, `const`).
1771
-
1772
- ```json
1773
- {
1774
- "title": "`x-messages`",
1775
- "description": "Validation error messages can be customized using the `x-messages` option in the schema. When defined as an object, messages can be applied by constraint (e.g., `minLength`, `const`).",
1776
- "type": "object",
1777
- "properties": {
1778
- "string": {
1779
- "type": "string",
1780
- "minLength": 5,
1781
- "const": "locoloco",
1782
- "x-messages": {
1783
- "minLength": "Need at least 5 sparks of brilliance.",
1784
- "const": "Only 'locoloco' unlocks the magic here."
1785
- }
1786
- }
1787
- }
1788
- }
1789
- ```
1790
-
1791
- Validation error messages can be customized using the `x-messages` option in the schema. When defined as an object, messages can be applied per language (e.g., `en`, `fr`) and constraint (e.g., `minLength`, `const`).
79
+ ```html
80
+ <div id="jedison-container"></div>
1792
81
 
1793
- ```json
1794
- {
1795
- "title": "`x-messages`",
1796
- "description": "Validation error messages can be customized using the `x-messages` option in the schema. When defined as an array, messages are defined per validation rule (e.g., `minLength`, `const`) and per language (e.g., `en`, `fr`).",
1797
- "type": "object",
1798
- "properties": {
1799
- "string": {
1800
- "type": "string",
1801
- "minLength": 5,
1802
- "const": "locoloco",
1803
- "x-messages": {
1804
- "en": {
1805
- "minLength": "Need at least 5 sparks of brilliance.",
1806
- "const": "Only 'locoloco' unlocks the magic here."
82
+ <script type="module">
83
+ import Jedison from 'jedison'
84
+
85
+ const jedison = new Jedison.Create({
86
+ container: document.querySelector('#jedison-container'),
87
+ theme: new Jedison.Theme(),
88
+ schema: {
89
+ "title": "Person",
90
+ "type": "object",
91
+ "properties": {
92
+ "name": {
93
+ "type": "string",
94
+ "description": "The person's name."
95
+ },
96
+ "age": {
97
+ "description": "Age in years which must be equal to or greater than zero.",
98
+ "type": "integer",
99
+ "minimum": 0
100
+ }
101
+ }
1807
102
  }
1808
- }
1809
- }
1810
- }
1811
- }
103
+ })
104
+ </script>
1812
105
  ```
1813
106
 
1814
- When defined as an array, the messages apply to all validation rules for the property.
1815
-
1816
- ```json
1817
- {
1818
- "title": "`x-messages`",
1819
- "description": "Validation error messages can be customized using the `x-messages` option in the schema. When defined as an array, the messages apply to all validation rules for the property.",
1820
- "type": "object",
1821
- "properties": {
1822
- "string": {
1823
- "type": "string",
1824
- "minLength": 5,
1825
- "x-messages": [
1826
- "5 chars please."
1827
- ]
1828
- }
1829
- }
1830
- }
1831
- ```
1832
-
1833
- ### `x-propertiesToggleContent`
1834
-
1835
- - Type: `boolean`
1836
- - Default: -
1837
- - Description: Text content for "properties" buttons.
1838
-
1839
- ### `x-showErrors`
1840
-
1841
- - Type: `string`
1842
- - Default: `"change"`
1843
- - Options: `"never"`, `"change"`, `"always"`
1844
- - Description: Determines when to display validation errors.
1845
-
1846
- Always show errors for this editor even if the value didn't change.
1847
-
1848
- ```json
1849
- {
1850
- "title": "Message",
1851
- "type": "string",
1852
- "x-showErrors": "always"
1853
- }
1854
- ```
1855
-
1856
- ### `x-sortable`
1857
-
1858
- - Type: `boolean`
1859
- - Default: `false`
1860
- - Description: Items can be sort via drag and drop if Sortable.js.
1861
-
1862
- ### `x-startCollapsed`
1863
-
1864
- - Type: `boolean`
1865
- - Description: Whether the editor should start expanded or collapsed. Works on editors that support collapse like `object` and `arrays`
1866
-
1867
- ### `x-switcherTitle`
1868
-
1869
- - Type: `string`
1870
- - Default: property name or `"title"`.
1871
- - Description: The text displayed in the multiple editor switcher to select this sub-schema editor.
1872
-
1873
- Switcher options displayed are:
1874
-
1875
- - "I want to pay with Credit Card"
1876
- - "I want to pay with PayPal"
1877
-
1878
- But in the sub-editors the titles remain:
1879
-
1880
- - "Card Number"
1881
- - "Email"
1882
-
1883
- ```json
1884
- {
1885
- "anyOf": [
1886
- {
1887
- "title": "Card Number",
1888
- "type": "string",
1889
- "x-switcherTitle": "I want to pay with Credit Card"
1890
- },
1891
- {
1892
- "title": "Email",
1893
- "type": "string",
1894
- "x-switcherTitle": "I want to pay with PayPal"
1895
- }
1896
- ]
1897
- }
1898
- ```
1899
-
1900
- ### `x-titleHidden`
1901
-
1902
- - Type: `boolean`
1903
- - Default: `false`
1904
- - Description: Hides the editor title.
1905
-
1906
- ### `x-titleIconClass`
1907
-
1908
- - Type: `string`
1909
- - Description: Icon class to use in titles if using any.
1910
-
1911
- Show a fontawesome envelope icon in the title.
1912
-
1913
- ```json
1914
- {
1915
- "title": "Message",
1916
- "type": "string",
1917
- "x-titleIconClass": "fas fa-envelope"
1918
- }
1919
- ```
1920
-
1921
- ### `x-titleTemplate`
1922
-
1923
- - Type: `string`
1924
- - Description: A template to form titles dynamically.
1925
-
1926
-
1927
107
  ## License
1928
108
 
1929
109
  Jedison is released under the MIT License, making it free for commercial and non-commercial use.