File tree Expand file tree Collapse file tree 4 files changed +81
-0
lines changed Expand file tree Collapse file tree 4 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -409,6 +409,12 @@ const errors = editor.validate({
409
409
});
410
410
```
411
411
412
+ Display validation errors on demand
413
+
414
+ ``` javascript
415
+ editor .showValidationErrors ();
416
+ ```
417
+
412
418
### Listen for Changes
413
419
414
420
The ` change ` event is fired whenever the editor's value changes.
Original file line number Diff line number Diff line change @@ -411,6 +411,15 @@ export class JSONEditor {
411
411
styleSheet . replaceSync ( cssText )
412
412
shadowRoot . adoptedStyleSheets = [ ...shadowRoot . adoptedStyleSheets , styleSheet ]
413
413
}
414
+
415
+ showValidationErrors ( ) {
416
+ const errors = this . validate ( )
417
+
418
+ Object . values ( this . editors ) . forEach ( editor => {
419
+ editor . is_dirty = true
420
+ editor . showValidationErrors ( errors )
421
+ } )
422
+ }
414
423
}
415
424
416
425
JSONEditor . defaults = defaults
Original file line number Diff line number Diff line change @@ -5,6 +5,18 @@ const { DEFAULT_WAIT_TIME } = require('./test-config')
5
5
6
6
Feature ( 'core' )
7
7
8
+ Scenario ( 'should show all validation errors on demand @editor-show-validation-errors' , async ( { I } ) => {
9
+ I . amOnPage ( 'editor-show-validation-errors.html' )
10
+ I . waitForElement ( '.je-ready' )
11
+ I . dontSee ( 'Value must be the constant value' )
12
+ I . dontSee ( 'Value must be at least 4 characters long' )
13
+ I . dontSee ( 'Value must be at least 4' )
14
+ I . click ( '#show-validation-errors' )
15
+ I . waitForText ( 'Value must be the constant value' )
16
+ I . waitForText ( 'Value must be at least 4 characters long' )
17
+ I . waitForText ( 'Value must be at least 4' )
18
+ } )
19
+
8
20
Scenario ( 'should enforce const @enforce_const' , async ( { I } ) => {
9
21
I . amOnPage ( 'enforce-const.html' )
10
22
I . waitForElement ( '.je-ready' )
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="utf-8 "/>
5
+ < title > showValidationErrors</ title >
6
+ < script src ="../../dist/jsoneditor.js "> </ script >
7
+ < link rel ="stylesheet " id ="theme-link " href ="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css ">
8
+ < link rel ="stylesheet " id ="iconlib-link " href ="https://use.fontawesome.com/releases/v5.6.1/css/all.css ">
9
+ </ head >
10
+ < body >
11
+
12
+ < div class ="container ">
13
+ < div id ='editor-container '> </ div >
14
+ < div class ="btn btn-success " id ="show-validation-errors "> Show validation errors</ div >
15
+ </ div >
16
+
17
+ < script >
18
+ const editorContainer = document . querySelector ( '#editor-container' )
19
+ const schema = {
20
+ "type" : "object" ,
21
+ "properties" : {
22
+ "boolean-checkbox" : {
23
+ "title" : "boolean-checkbox" ,
24
+ "type" : "boolean" ,
25
+ "format" : "checkbox" ,
26
+ "const" : true ,
27
+ "default" : false
28
+ } ,
29
+ "minLength" : {
30
+ "type" : "string" ,
31
+ "minLength" : 4 ,
32
+ } ,
33
+ "minimum" : {
34
+ "type" : "number" ,
35
+ "minimum" : 4 ,
36
+ }
37
+ }
38
+ }
39
+
40
+ const editor = new JSONEditor ( editorContainer , {
41
+ schema : schema ,
42
+ theme : 'bootstrap4' ,
43
+ iconlib : 'fontawesome'
44
+ } )
45
+
46
+ const showValidationErrors = document . querySelector ( '#show-validation-errors' )
47
+
48
+ showValidationErrors . addEventListener ( 'click' , ( ) => {
49
+ editor . showValidationErrors ( )
50
+ } )
51
+ </ script >
52
+
53
+ </ body >
54
+ </ html >
You can’t perform that action at this time.
0 commit comments