Skip to content

Commit

Permalink
Fix _unchecked session removal for arrays
Browse files Browse the repository at this point in the history
Using triple `=== ['_unchecked']` can never return `true`
  • Loading branch information
colinrotherham committed Oct 11, 2023
1 parent 89a909c commit bc86613
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function storeData (input, data) {
let val = input[i]

// Delete values when users unselect checkboxes
if (val === '_unchecked' || val === ['_unchecked']) {
if ([val].flat().every((item) => item === '_unchecked')) {
delete data[i]
continue
}
Expand Down
2 changes: 1 addition & 1 deletion lib/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('autoStoreData', () => {
}
const expectedData = {
checkBoxes1: ['cb1-1', 'cb1-2'],
checkBoxes2: [],
checkBoxes2: undefined,
checkBoxes3: ['cb3-1', 'cb3-2'],
existingData: 'existing data'
}
Expand Down

0 comments on commit bc86613

Please sign in to comment.