DEV: add addError method to FormKit onRegisterApi (#28436)

This commit adds the addError method to From's onRegisterApi to allow
parent components to add errors to a field.
This commit is contained in:
锦心 2024-08-20 17:22:36 +08:00 committed by GitHub
parent e9b427ff53
commit 070025204d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View File

@ -42,6 +42,7 @@ class FKForm extends Component {
setProperties: this.setProperties,
submit: this.onSubmit,
reset: this.onReset,
addError: this.addError,
});
this.router.on("routeWillChange", this.checkIsDirty);

View File

@ -137,6 +137,12 @@ module("Integration | Component | FormKit | Form", function (hooks) {
await formApi.submit();
assert.dom(".bar").hasText("2");
formApi.addError("bar", { title: "Bar", message: "error_foo" });
// assert on the next tick
setTimeout(() => {
assert.form().hasErrors({ bar: "error_foo" });
}, 0);
});
test("@data", async function (assert) {