Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-1477 userData incorrect when unchecking defaulted selected checkboxes #1478

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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([])
})
})