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:
Joffrey JAFFEUX 2024-07-18 14:33:08 +02:00 committed by GitHub
parent 94d4b187ef
commit 4c8812737c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View File

@ -36,6 +36,7 @@ class FKForm extends Component {
this.args.onRegisterApi?.({
set: this.set,
setProperties: this.setProperties,
submit: this.onSubmit,
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
registerField(name, field) {
if (!name) {
@ -283,6 +291,7 @@ class FKForm extends Component {
triggerRevalidationFor=this.triggerRevalidationFor
)
set=this.set
setProperties=this.setProperties
addItemToCollection=this.addItemToCollection
)
this.formData.draftData

View File

@ -213,4 +213,22 @@ module("Integration | Component | FormKit | Form", function (hooks) {
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");
});
});