DEV: add addError method to FormKit onRegisterApi ()

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
app/assets/javascripts/discourse
app/form-kit/components/fk
tests/integration/components/form-kit

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

@ -137,6 +137,12 @@ module("Integration | Component | FormKit | Form", function (hooks) {
await formApi.submit(); await formApi.submit();
assert.dom(".bar").hasText("2"); 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) { test("@data", async function (assert) {