Merge pull request #255 from bcromijn/master
fix(lion-radio-group): handle unchecked state
This commit is contained in:
commit
6559b34964
2 changed files with 31 additions and 2 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue