DEV: supports setProperties (#27969)
This is a convenience for when you have multiple properties to set in form kit. ``` // before set("foo", 1); set("bar", 2); //after setProperties({foo: 1, bar: 2}); ```
This commit is contained in:
parent
94d4b187ef
commit
4c8812737c
|
@ -36,6 +36,7 @@ class FKForm extends Component {
|
||||||
|
|
||||||
this.args.onRegisterApi?.({
|
this.args.onRegisterApi?.({
|
||||||
set: this.set,
|
set: this.set,
|
||||||
|
setProperties: this.setProperties,
|
||||||
submit: this.onSubmit,
|
submit: this.onSubmit,
|
||||||
reset: this.onReset,
|
reset: this.onReset,
|
||||||
});
|
});
|
||||||
|
@ -121,6 +122,13 @@ class FKForm extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
async setProperties(object) {
|
||||||
|
for (const [name, value] of Object.entries(object)) {
|
||||||
|
await this.set(name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
registerField(name, field) {
|
registerField(name, field) {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
@ -283,6 +291,7 @@ class FKForm extends Component {
|
||||||
triggerRevalidationFor=this.triggerRevalidationFor
|
triggerRevalidationFor=this.triggerRevalidationFor
|
||||||
)
|
)
|
||||||
set=this.set
|
set=this.set
|
||||||
|
setProperties=this.setProperties
|
||||||
addItemToCollection=this.addItemToCollection
|
addItemToCollection=this.addItemToCollection
|
||||||
)
|
)
|
||||||
this.formData.draftData
|
this.formData.draftData
|
||||||
|
|
|
@ -213,4 +213,22 @@ module("Integration | Component | FormKit | Form", function (hooks) {
|
||||||
|
|
||||||
assert.dom(".foo").hasText("2");
|
assert.dom(".foo").hasText("2");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("yielded setProperties", async function (assert) {
|
||||||
|
await render(<template>
|
||||||
|
<Form @data={{hash foo=1 bar=1}} as |form data|>
|
||||||
|
<div class="foo">{{data.foo}}</div>
|
||||||
|
<div class="bar">{{data.bar}}</div>
|
||||||
|
<form.Button
|
||||||
|
class="test"
|
||||||
|
@action={{fn form.setProperties (hash foo=2 bar=2)}}
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
|
</template>);
|
||||||
|
|
||||||
|
await click(".test");
|
||||||
|
|
||||||
|
assert.dom(".foo").hasText("2");
|
||||||
|
assert.dom(".bar").hasText("2");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue