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