Skip to content

A platform for community discussion. Free, open, simple.

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

锦心070025204dbe
diff --git a/app/assets/javascripts/discourse/app/form-kit/components/fk/form.gjs b/app/assets/javascripts/discourse/app/form-kit/components/fk/form.gjs
index 9614e1f58a2..124e70eb173 100644
--- a/app/assets/javascripts/discourse/app/form-kit/components/fk/form.gjs
+++ b/app/assets/javascripts/discourse/app/form-kit/components/fk/form.gjs
@@ -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);
diff --git a/app/assets/javascripts/discourse/tests/integration/components/form-kit/form-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/form-kit/form-test.gjs
index 7a82f94aaff..52784b3e06e 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/form-kit/form-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/form-kit/form-test.gjs
@@ -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) {