@@ -225,11 +225,24 @@ export function getArrayFormRow(args) {
225225 schema = { schema }
226226 addable = { addable }
227227 onAdd = { ( ) => onAdd ( getBlankData ( schema . items ) , coords ) }
228+ editable = { args . editable }
229+ onEdit = { args . onEdit }
228230 key = { 'row_group_' + name }
229231 >
230232 { rows }
231233 </ FormGroup >
232234 ) ;
235+
236+ if ( args . parentType === 'object' && args . removable ) {
237+ rows = (
238+ < div className = "rjf-form-group-wrapper" key = { 'row_group_wrapper_' + name } >
239+ < FormRowControls
240+ onRemove = { ( e ) => onRemove ( name ) }
241+ />
242+ { rows }
243+ </ div >
244+ ) ;
245+ }
233246 }
234247
235248 if ( groups . length ) {
@@ -282,7 +295,15 @@ export function getObjectFormRow(args) {
282295 let key = keys [ i ] ;
283296 let value = data [ key ] ;
284297 let childName = name + '-' + key ;
285- let schemaValue = schema_keys [ key ] || { type : 'string' } ;
298+ let schemaValue = schema_keys [ key ] ; // || {type: 'string'};
299+
300+ if ( typeof schemaValue === 'undefined' ) {
301+ // for keys added through additionalProperties
302+ if ( typeof schema . additionalProperties === 'boolean' )
303+ schemaValue = { type : 'string' } ;
304+ else
305+ schemaValue = { ...schema . additionalProperties } ;
306+ }
286307
287308 let type = schemaValue . type ;
288309
@@ -311,13 +332,14 @@ export function getObjectFormRow(args) {
311332 parentType : 'object' ,
312333 } ;
313334
335+ nextArgs . onEdit = ( ) => handleKeyEdit ( data , key , value , childName , onAdd , onRemove ) ;
336+ nextArgs . editable = removable ;
337+
314338 if ( type === 'array' ) {
315339 rows . push ( getArrayFormRow ( nextArgs ) ) ;
316340 } else if ( type === 'object' ) {
317341 rows . push ( getObjectFormRow ( nextArgs ) ) ;
318342 } else {
319- nextArgs . onEdit = ( ) => handleKeyEdit ( data , key , value , childName , onAdd , onRemove ) ;
320- nextArgs . editable = removable ;
321343 rows . push ( getStringFormRow ( nextArgs ) ) ;
322344 }
323345 }
@@ -334,30 +356,46 @@ export function getObjectFormRow(args) {
334356 level = { level }
335357 schema = { schema }
336358 addable = { schema . additionalProperties }
337- onAdd = { ( ) => handleKeyValueAdd ( data , coords , onAdd ) }
359+ onAdd = { ( ) => handleKeyValueAdd ( data , coords , onAdd , schema . additionalProperties ) }
360+ editable = { args . editable }
361+ onEdit = { args . onEdit }
338362 key = { 'row_group_' + name }
339363 >
340364 { rows }
341365 </ FormGroup >
342366 ) ;
367+ if ( args . parentType === 'object' && args . removable ) {
368+ rows = (
369+ < div className = "rjf-form-group-wrapper" key = { 'row_group_wrapper_' + name } >
370+ < FormRowControls
371+ onRemove = { ( e ) => onRemove ( name ) }
372+ />
373+ { rows }
374+ </ div >
375+ ) ;
376+ }
377+
343378 }
344379
345380 return rows ;
346381}
347382
348383
349- function handleKeyValueAdd ( data , coords , onAdd ) {
384+ function handleKeyValueAdd ( data , coords , onAdd , newSchema ) {
350385 let key = prompt ( "Add new key" ) ;
351386 if ( key === null ) // clicked cancel
352387 return ;
353388
389+ if ( newSchema === true )
390+ newSchema = { type : 'string' } ;
391+
354392 key = key . trim ( ) ;
355393 if ( ! key )
356394 alert ( "(!) Can't add empty key.\r\n\r\n" ) ;
357395 else if ( data . hasOwnProperty ( key ) )
358396 alert ( "(!) Duplicate keys not allowed. This key already exists.\r\n\r\n" ) ;
359397 else
360- onAdd ( "" , coords + '-' + key ) ;
398+ onAdd ( getBlankData ( newSchema ) , coords + '-' + key ) ;
361399}
362400
363401
0 commit comments