fix(choice-input): fix serializedValue setter check

This commit is contained in:
Joren Broekema 2020-03-12 15:37:09 +01:00 committed by Thomas Allmer
parent 77abd7c8b0
commit 0445b86350
2 changed files with 15 additions and 3 deletions

View file

@ -1,5 +1,5 @@
import { dedupeMixin } from '@lion/core';
import { InteractionStateMixin, FormRegistrarMixin } from '@lion/field';
import { FormRegistrarMixin, InteractionStateMixin } from '@lion/field';
export const ChoiceGroupMixin = dedupeMixin(
superclass =>
@ -49,7 +49,7 @@ export const ChoiceGroupMixin = dedupeMixin(
}
set serializedValue(value) {
this._setCheckedElements(value, (el, val) => el.serializedValue === val);
this._setCheckedElements(value, (el, val) => el.serializedValue.value === val);
}
constructor() {

View file

@ -1,11 +1,11 @@
import { html, LitElement } from '@lion/core';
import { FormGroupMixin } from '@lion/fieldset';
import '@lion/fieldset/lion-fieldset.js';
import { LionInput } from '@lion/input';
import { Required } from '@lion/validate';
import { expect, fixture, nextFrame } from '@open-wc/testing';
import { ChoiceGroupMixin } from '../src/ChoiceGroupMixin.js';
import { ChoiceInputMixin } from '../src/ChoiceInputMixin.js';
import '@lion/fieldset/lion-fieldset.js';
describe('ChoiceGroupMixin', () => {
before(() => {
@ -116,6 +116,18 @@ describe('ChoiceGroupMixin', () => {
expect(el.formElements[2].checked).to.be.true;
});
it('can set initial serializedValue on creation', async () => {
const el = await fixture(html`
<choice-group name="gender" .serializedValue=${'other'}>
<choice-group-input .choiceValue=${'male'}></choice-group-input>
<choice-group-input .choiceValue=${'female'}></choice-group-input>
<choice-group-input .choiceValue=${'other'}></choice-group-input>
</choice-group>
`);
expect(el.serializedValue).to.equal('other');
});
it('can handle complex data via choiceValue', async () => {
const date = new Date(2018, 11, 24, 10, 33, 30, 0);