@@ -2,7 +2,8 @@ import {getBlankData} from './data';
22import { Button , FormInput , FormCheckInput , FormRadioInput , FormSelectInput ,
33 FormFileInput , FormRow , FormGroup , GroupTitle , FormRowControls , FormTextareaInput ,
44 FormDateTimeInput , FormMultiSelectInput , FileUploader , AutoCompleteInput } from './components' ;
5- import { getVerboseName , convertType , getCoordsFromName , getKeyword , normalizeKeyword } from './util' ;
5+ import { getVerboseName , convertType , getCoordsFromName , getKeyword , normalizeKeyword ,
6+ joinCoords , splitCoords } from './util' ;
67
78
89function handleChange ( e , fieldType , callback ) {
@@ -240,17 +241,17 @@ export function getArrayFormRow(args) {
240241
241242 for ( let i = 0 ; i < data . length ; i ++ ) {
242243 nextArgs . data = data [ i ] ;
243- nextArgs . name = name + '-' + i ;
244+ nextArgs . name = joinCoords ( name , i ) ;
244245
245246 if ( i === 0 )
246247 nextArgs . onMoveUp = null ;
247248 else
248- nextArgs . onMoveUp = ( e ) => onMove ( name + '-' + i , name + '-' + ( i - 1 ) ) ;
249+ nextArgs . onMoveUp = ( e ) => onMove ( joinCoords ( name , i ) , joinCoords ( name , i - 1 ) ) ;
249250
250251 if ( i === data . length - 1 )
251252 nextArgs . onMoveDown = null ;
252253 else
253- nextArgs . onMoveDown = ( e ) => onMove ( name + '-' + i , name + '-' + ( i + 1 ) ) ;
254+ nextArgs . onMoveDown = ( e ) => onMove ( joinCoords ( name , i ) , joinCoords ( name , i + 1 ) ) ;
254255
255256 if ( type === 'array' ) {
256257 groups . push ( getArrayFormRow ( nextArgs ) ) ;
@@ -312,9 +313,9 @@ export function getArrayFormRow(args) {
312313 { groups . map ( ( i , index ) => (
313314 < div className = "rjf-form-group-wrapper" key = { 'group_wrapper_' + name + '_' + index } >
314315 < FormRowControls
315- onRemove = { removable ? ( e ) => onRemove ( name + '-' + index ) : null }
316- onMoveUp = { index > 0 ? ( e ) => onMove ( name + '-' + index , name + '-' + ( index - 1 ) ) : null }
317- onMoveDown = { index < groups . length - 1 ? ( e ) => onMove ( name + '-' + index , name + '-' + ( index + 1 ) ) : null }
316+ onRemove = { removable ? ( e ) => onRemove ( joinCoords ( name , index ) ) : null }
317+ onMoveUp = { index > 0 ? ( e ) => onMove ( joinCoords ( name , index ) , joinCoords ( name , index - 1 ) ) : null }
318+ onMoveDown = { index < groups . length - 1 ? ( e ) => onMove ( joinCoords ( name , index ) , joinCoords ( name , index + 1 ) ) : null }
318319 />
319320 { i }
320321 </ div >
@@ -354,7 +355,7 @@ export function getObjectFormRow(args) {
354355 for ( let i = 0 ; i < keys . length ; i ++ ) {
355356 let key = keys [ i ] ;
356357 let value = data [ key ] ;
357- let childName = name + '-' + key ;
358+ let childName = joinCoords ( name , key ) ;
358359 let schemaValue = schema_keys . hasOwnProperty ( key ) ? { ...schema_keys [ key ] } : undefined ;
359360
360361 if ( typeof schemaValue === 'undefined' ) {
@@ -458,7 +459,7 @@ function handleKeyValueAdd(data, coords, onAdd, newSchema, getRef) {
458459 else if ( data . hasOwnProperty ( key ) )
459460 alert ( "(!) Duplicate keys not allowed. This key already exists.\r\n\r\n" ) ;
460461 else
461- onAdd ( getBlankData ( newSchema , getRef ) , coords + '-' + key ) ;
462+ onAdd ( getBlankData ( newSchema , getRef ) , joinCoords ( coords , key ) ) ;
462463}
463464
464465
@@ -477,10 +478,10 @@ function handleKeyEdit(data, key, value, coords, onEdit) {
477478 else if ( data . hasOwnProperty ( newKey ) )
478479 return alert ( "(!) Duplicate keys not allowed. This key already exists.\r\n\r\n" ) ;
479480
480- let newCoords = coords . split ( '-' ) ;
481+ let newCoords = splitCoords ( coords ) ;
481482 newCoords . pop ( ) ;
482483 newCoords . push ( newKey ) ;
483- newCoords = newCoords . join ( '-' ) ;
484+ newCoords = joinCoords . apply ( null , newCoords ) ;
484485
485486
486487 onEdit ( value , newCoords , coords ) ;
0 commit comments