@@ -375,7 +375,7 @@ export function updateValue(value, attrs, store = true) {
375375 }
376376}
377377
378- export function copyValue ( ...originalValues ) {
378+ export function copyValue ( question , ...originalValues ) {
379379 const firstValue = first ( originalValues )
380380 const pendingId = `copyValue/${ firstValue . attribute } /${ firstValue . set_prefix } /${ firstValue . set_index } `
381381
@@ -390,22 +390,33 @@ export function copyValue(...originalValues) {
390390 ...copies ,
391391 ...sets . filter ( ( set ) => (
392392 ( set . set_prefix == value . set_prefix ) &&
393- ( set . set_index != value . set_index )
393+ ( set . set_index != value . set_index ) &&
394+ ( set . element == question . parent )
394395 ) ) . map ( ( set ) => {
395- const siblingIndex = values . findIndex ( ( v ) => (
396+ // check if every sibling is empty
397+ if ( values . filter ( ( v ) => (
396398 ( v . attribute == value . attribute ) &&
397399 ( v . set_prefix == set . set_prefix ) &&
398- ( v . set_index == set . set_index ) &&
399- ( v . collection_index == value . collection_index )
400- ) )
401-
402- const sibling = siblingIndex > 0 ? values [ siblingIndex ] : null
403-
404- if ( isNil ( sibling ) ) {
405- return [ ValueFactory . create ( { ...value , set_index : set . set_index } ) , siblingIndex ]
406- } else if ( isEmptyValue ( sibling ) ) {
407- // the spread operator { ...sibling } does prevent an update in place
408- return [ ValueFactory . update ( { ...sibling } , value ) , siblingIndex ]
400+ ( v . set_index == set . set_index )
401+ ) ) . every ( v => isEmptyValue ( v ) ) ) {
402+ // find the corresponding sibling to this original value
403+ const siblingIndex = values . findIndex ( ( v ) => (
404+ ( v . attribute == value . attribute ) &&
405+ ( v . set_prefix == set . set_prefix ) &&
406+ ( v . set_index == set . set_index ) &&
407+ ( v . collection_index == value . collection_index )
408+ ) )
409+
410+ const sibling = siblingIndex > 0 ? values [ siblingIndex ] : null
411+
412+ if ( isNil ( sibling ) ) {
413+ return [ ValueFactory . create ( { ...value , set_index : set . set_index } ) , siblingIndex ]
414+ } else if ( isEmptyValue ( sibling ) ) {
415+ // the spread operator { ...sibling } does prevent an update in place
416+ return [ ValueFactory . update ( { ...sibling } , value ) , siblingIndex ]
417+ } else {
418+ return null
419+ }
409420 } else {
410421 return null
411422 }
0 commit comments