@@ -990,27 +990,28 @@ function cloneHTMLElement(element) {
990
990
return newElement ;
991
991
}
992
992
993
- function getArrayValue ( element , value , currentValue ) {
994
- if ( ! ( currentValue instanceof Array ) ) {
995
- currentValue = [ ] ;
993
+ function updateArrayDataFromChangedElement ( element , value , currentValues ) {
994
+ if ( ! ( currentValues instanceof Array ) ) {
995
+ currentValues = [ ] ;
996
996
}
997
997
if ( element instanceof HTMLInputElement && element . type === 'checkbox' ) {
998
- const index = currentValue . indexOf ( value ) ;
998
+ const index = currentValues . indexOf ( value ) ;
999
999
if ( element . checked ) {
1000
1000
if ( index === - 1 ) {
1001
- currentValue . push ( value ) ;
1001
+ currentValues . push ( value ) ;
1002
1002
}
1003
+ return currentValues ;
1003
1004
}
1004
- else {
1005
- if ( index > - 1 ) {
1006
- currentValue . splice ( index , 1 ) ;
1007
- }
1005
+ if ( index > - 1 ) {
1006
+ currentValues . splice ( index , 1 ) ;
1008
1007
}
1008
+ return currentValues ;
1009
1009
}
1010
- else if ( element instanceof HTMLSelectElement ) {
1011
- currentValue = Array . from ( element . selectedOptions ) . map ( el => el . value ) ;
1010
+ if ( element instanceof HTMLSelectElement ) {
1011
+ currentValues = Array . from ( element . selectedOptions ) . map ( el => el . value ) ;
1012
+ return currentValues ;
1012
1013
}
1013
- return currentValue ;
1014
+ throw new Error ( `The element used to determine array data from is unsupported ( ${ element . tagName } provided)` ) ;
1014
1015
}
1015
1016
1016
1017
const DEFAULT_DEBOUNCE = 150 ;
@@ -1123,7 +1124,7 @@ class default_1 extends Controller {
1123
1124
if ( / \[ ] $ / . test ( model ) ) {
1124
1125
const { currentLevelData, finalKey } = parseDeepData ( this . dataValue , normalizeModelName ( model ) ) ;
1125
1126
const currentValue = currentLevelData [ finalKey ] ;
1126
- value = getArrayValue ( element , value , currentValue ) ;
1127
+ value = updateArrayDataFromChangedElement ( element , value , currentValue ) ;
1127
1128
}
1128
1129
else if ( element instanceof HTMLInputElement
1129
1130
&& element . type === 'checkbox'
0 commit comments