File tree Expand file tree Collapse file tree 2 files changed +87
-9
lines changed
Expand file tree Collapse file tree 2 files changed +87
-9
lines changed Original file line number Diff line number Diff line change @@ -1049,20 +1049,19 @@ export class ObjectEditor extends AbstractEditor {
10491049 return undefined
10501050 }
10511051 const result = super . getValue ( )
1052- const isEmpty = i => typeof result [ i ] === 'undefined' || result [ i ] === '' ||
1052+ const isEmpty = obj => typeof obj === 'undefined' || obj === '' ||
10531053 (
1054- result [ i ] === Object ( result [ i ] ) &&
1055- Object . keys ( result [ i ] ) . length === 0 &&
1056- result [ i ] . constructor === Object
1054+ obj === Object ( obj ) &&
1055+ Object . keys ( obj ) . length === 0 &&
1056+ obj . constructor === Object
10571057 )
1058- if ( this . jsoneditor . options . remove_empty_properties || this . options . remove_empty_properties ) {
1059- Object . keys ( result ) . forEach ( i => {
1060- if ( isEmpty ( i ) ) {
1061- delete result [ i ]
1058+ if ( result && ( this . jsoneditor . options . remove_empty_properties || this . options . remove_empty_properties ) ) {
1059+ Object . keys ( result ) . forEach ( key => {
1060+ if ( isEmpty ( result [ key ] ) ) {
1061+ delete result [ key ]
10621062 }
10631063 } )
10641064 }
1065-
10661065 return result
10671066 }
10681067
Original file line number Diff line number Diff line change 1+ import { JSONEditor } from '../../../src/core'
2+
3+ const fixture = [
4+ {
5+ title : 'Object Editor Test' ,
6+ schema : {
7+ type : 'object' ,
8+ required : [
9+ 'name'
10+ ] ,
11+ properties : {
12+ name : {
13+ type : 'string' ,
14+ default : 'Jeremy Dorn'
15+ }
16+ }
17+ } ,
18+ value : {
19+ name : 'Jeremy Dorn'
20+ }
21+ } ,
22+ {
23+ title : 'remove_empty_properties test' ,
24+ schema : {
25+ type : 'object' ,
26+ required : [
27+ 'name'
28+ ] ,
29+ properties : {
30+ name : {
31+ type : 'string' ,
32+ default : 'Jeremy Dorn'
33+ } ,
34+ location : {
35+ type : 'object' ,
36+ properties : {
37+ city : {
38+ type : 'string'
39+ }
40+ } ,
41+ options : {
42+ remove_empty_properties : true
43+ }
44+ }
45+ } ,
46+ options : {
47+ remove_empty_properties : true
48+ }
49+ } ,
50+ value : {
51+ name : 'Jeremy Dorn'
52+ }
53+ }
54+ ]
55+
56+ describe ( 'Object Editor' , ( ) => {
57+ let element
58+ let editor
59+
60+ beforeEach ( ( ) => {
61+ document . body . insertAdjacentHTML (
62+ 'afterbegin' ,
63+ '<div id="fixture"></div>' )
64+ element = document . getElementById ( 'fixture' )
65+ } )
66+
67+ afterEach ( ( ) => {
68+ editor . destroy ( )
69+ } )
70+
71+ fixture . forEach ( spec => {
72+ it ( spec . title , ( ) => {
73+ editor = new JSONEditor ( element , {
74+ schema : spec . schema
75+ } )
76+ expect ( editor . getValue ( ) ) . toEqual ( spec . value )
77+ } )
78+ } )
79+ } )
You can’t perform that action at this time.
0 commit comments