Skip to content

Commit

Permalink
Merge pull request #1478 from lucasnetau/fix-1477
Browse files Browse the repository at this point in the history
Fix GH-1477 userData incorrect when unchecking defaulted selected checkboxes
  • Loading branch information
kevinchappell authored Nov 1, 2023
2 parents 8da5434 + 2744a68 commit bf73b76
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/form-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class FormRender {
// Skip disabled fields -- This will not have user data available
if (definedField.disabled) continue

definedField.userData = userDataMap[definedField.name]
definedField.userData = userDataMap[definedField.name] ?? []
}
})

Expand Down
26 changes: 26 additions & 0 deletions tests/form-render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,30 @@ describe('Form Rendering', () => {
textarea = container.find('#textarea-elem')
expect(textarea).not.toHaveLength(0)
})

test('check userData when no value set', () => {
const container = $('<div>')
const formData = [
{type: 'textarea', name: 'input-textarea'},
{type: 'text', name: 'input-text'},
{type: 'checkbox-group', name: 'input-checkbox-group', 'values': [ { 'label': 'O', 'value': 'option-1', 'selected': false }, ]},
{type: 'radio-group', name: 'input-radio-group', 'values': [ { 'label': 'O', 'value': 'option-1', 'selected': false }, ]},
{type: 'select', name: 'input-select', placeholder: 'Select...', 'values': [ { 'label': 'O', 'value': 'option-1', 'selected': false }, ]},
{type: 'select', name: 'input-select-multiple', placeholder: 'Select...', multiple: true, 'values': [ { 'label': 'O', 'value': 'option-1', 'selected': false }, ]},
]
container.formRender({ formData })

const userData = {}

container.formRender('userData').forEach(elem => {
userData[elem.name] = elem.userData
})

expect(userData['input-textarea']).toStrictEqual([''])
expect(userData['input-text']).toStrictEqual([''])
expect(userData['input-checkbox-group']).toStrictEqual([])
expect(userData['input-radio-group']).toStrictEqual([])
expect(userData['input-select']).toStrictEqual([])
expect(userData['input-select-multiple']).toStrictEqual([])
})
})

0 comments on commit bf73b76

Please sign in to comment.