1
- /*! JSON Editor v0.7.11 - JSON Schema -> HTML Editor
1
+ /*! JSON Editor v0.7.12 - JSON Schema -> HTML Editor
2
2
* By Jeremy Dorn - https://github.com/jdorn/json-editor/
3
3
* Released under the MIT license
4
4
*
5
- * Date: 2014-09-28
5
+ * Date: 2014-10-05
6
6
*/
7
7
8
8
/**
@@ -307,6 +307,8 @@ JSONEditor.prototype = {
307
307
this . callbacks = this . callbacks || { } ;
308
308
this . callbacks [ event ] = this . callbacks [ event ] || [ ] ;
309
309
this . callbacks [ event ] . push ( callback ) ;
310
+
311
+ return this ;
310
312
} ,
311
313
off : function ( event , callback ) {
312
314
// Specific callback
@@ -329,13 +331,29 @@ JSONEditor.prototype = {
329
331
else {
330
332
this . callbacks = { } ;
331
333
}
334
+
335
+ return this ;
332
336
} ,
333
337
trigger : function ( event ) {
334
338
if ( this . callbacks && this . callbacks [ event ] && this . callbacks [ event ] . length ) {
335
339
for ( var i = 0 ; i < this . callbacks [ event ] . length ; i ++ ) {
336
340
this . callbacks [ event ] [ i ] ( ) ;
337
341
}
338
342
}
343
+
344
+ return this ;
345
+ } ,
346
+ setOption : function ( option , value ) {
347
+ if ( option === "show_errors" ) {
348
+ this . options . show_errors = value ;
349
+ this . onChange ( ) ;
350
+ }
351
+ // Only the `show_errors` option is supported for now
352
+ else {
353
+ throw "Option " + option + " must be set during instantiation and cannot be changed later" ;
354
+ }
355
+
356
+ return this ;
339
357
} ,
340
358
getEditorClass : function ( schema ) {
341
359
var classname ;
@@ -378,10 +396,15 @@ JSONEditor.prototype = {
378
396
if ( self . options . show_errors !== "never" ) {
379
397
self . root . showValidationErrors ( self . validation_results ) ;
380
398
}
399
+ else {
400
+ self . root . showValidationErrors ( [ ] ) ;
401
+ }
381
402
382
403
// Fire change event
383
404
self . trigger ( 'change' ) ;
384
405
} ) ;
406
+
407
+ return this ;
385
408
} ,
386
409
compileTemplate : function ( template , name ) {
387
410
name = name || JSONEditor . defaults . template ;
@@ -687,10 +710,10 @@ JSONEditor.prototype = {
687
710
} , [ ] ) ;
688
711
}
689
712
// Type should be intersected and is either an array or string
690
- else if ( prop === 'type' ) {
713
+ else if ( prop === 'type' && ( typeof val === "string" || Array . isArray ( val ) ) ) {
691
714
// Make sure we're dealing with arrays
692
- if ( typeof val !== "object ") val = [ val ] ;
693
- if ( typeof obj2 . type !== "object ") obj2 . type = [ obj2 . type ] ;
715
+ if ( typeof val === "string ") val = [ val ] ;
716
+ if ( typeof obj2 . type === "string ") obj2 . type = [ obj2 . type ] ;
694
717
695
718
696
719
extended . type = val . filter ( function ( n ) {
@@ -2104,9 +2127,9 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
2104
2127
var self = this ;
2105
2128
2106
2129
if ( this . jsoneditor . options . show_errors === "always" ) { }
2107
- else if ( ! this . is_dirty ) return ;
2108
-
2130
+ else if ( ! this . is_dirty && this . previous_error_setting === this . jsoneditor . options . show_errors ) return ;
2109
2131
2132
+ this . previous_error_setting = this . jsoneditor . options . show_errors ;
2110
2133
2111
2134
var messages = [ ] ;
2112
2135
$each ( errors , function ( i , error ) {
0 commit comments