Merge pull request #255 from bcromijn/master

fix(lion-radio-group): handle unchecked state
This commit is contained in:
Joren Broekema 2019-09-17 09:00:16 -07:00 committed by GitHub
commit 6559b34964
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -35,7 +35,8 @@ export class LionRadioGroup extends LionFieldset {
} }
get serializedValue() { get serializedValue() {
return this._getCheckedRadioElement().serializedValue; const el = this._getCheckedRadioElement();
return el ? el.serializedValue : '';
} }
set serializedValue(value) { set serializedValue(value) {
@ -43,7 +44,8 @@ export class LionRadioGroup extends LionFieldset {
} }
get formattedValue() { get formattedValue() {
return this._getCheckedRadioElement().formattedValue; const el = this._getCheckedRadioElement();
return el ? el.formattedValue : '';
} }
set formattedValue(value) { set formattedValue(value) {

View file

@ -211,4 +211,31 @@ describe('<lion-radio-group>', () => {
el.formElements['gender[]'][0].choiceChecked = true; el.formElements['gender[]'][0].choiceChecked = true;
expect(el.error.required).to.be.undefined; expect(el.error.required).to.be.undefined;
}); });
it('returns serialized value', async () => {
const group = await fixture(html`
<lion-radio-group .errorValidators="${[['required']]}">
<lion-radio name="gender[]" .choiceValue=${'male'}></lion-radio>
<lion-radio name="gender[]" .choiceValue=${'female'}></lion-radio>
</lion-radio-group>
`);
await nextFrame();
group.formElements['gender[]'][0].choiceChecked = true;
expect(group.serializedValue).to.deep.equal({ checked: true, value: 'male' });
});
it('returns serialized value on unchecked state', async () => {
const group = await fixture(html`
<lion-radio-group .errorValidators="${[['required']]}">
<lion-radio name="gender[]" .choiceValue=${'male'}></lion-radio>
<lion-radio name="gender[]" .choiceValue=${'female'}></lion-radio>
</lion-radio-group>
`);
await nextFrame();
expect(group.serializedValue).to.deep.equal('');
});
}); });