Merge pull request #406 from ing-bank/fix/set-initial-fieldset-value
fix(fieldset): wait for registration before setting values
This commit is contained in:
commit
fb6b77e790
2 changed files with 35 additions and 1 deletions
|
|
@ -266,7 +266,11 @@ export class LionFieldset extends FormRegistrarMixin(
|
|||
});
|
||||
}
|
||||
|
||||
_setValueMapForAllFormElements(property, values) {
|
||||
async _setValueMapForAllFormElements(property, values) {
|
||||
if (!this.__readyForRegistration) {
|
||||
await this.registrationReady;
|
||||
}
|
||||
|
||||
if (values && typeof values === 'object') {
|
||||
Object.keys(values).forEach(name => {
|
||||
if (Array.isArray(this.formElements[name])) {
|
||||
|
|
|
|||
|
|
@ -260,6 +260,36 @@ describe('<lion-fieldset>', () => {
|
|||
expect(el.formElements.sub.formElements['hobbies[]'][1].disabled).to.be.true;
|
||||
});
|
||||
|
||||
it('can set initial modelValue on creation', async () => {
|
||||
const initialModelValue = {
|
||||
lastName: 'Bar',
|
||||
};
|
||||
const el = await fixture(html`
|
||||
<${tag} .modelValue=${initialModelValue}>
|
||||
<${childTag} name="lastName"></${childTag}>
|
||||
</${tag}>
|
||||
`);
|
||||
|
||||
await el.registrationReady;
|
||||
await el.updateComplete;
|
||||
expect(el.modelValue).to.eql(initialModelValue);
|
||||
});
|
||||
|
||||
it('can set initial serializedValue on creation', async () => {
|
||||
const initialSerializedValue = {
|
||||
lastName: 'Bar',
|
||||
};
|
||||
const el = await fixture(html`
|
||||
<${tag} .modelValue=${initialSerializedValue}>
|
||||
<${childTag} name="lastName"></${childTag}>
|
||||
</${tag}>
|
||||
`);
|
||||
|
||||
await el.registrationReady;
|
||||
await el.updateComplete;
|
||||
expect(el.modelValue).to.eql(initialSerializedValue);
|
||||
});
|
||||
|
||||
describe('validation', () => {
|
||||
it('validates on init', async () => {
|
||||
class IsCat extends Validator {
|
||||
|
|
|
|||
Loading…
Reference in a new issue