A platform for community discussion. Free, open, simple.
FIX: allows to manually remove error for virtual fields (#28555)
Joffrey JAFFEUX27f08a5c28b0
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-badges/show.js b/app/assets/javascripts/admin/addon/controllers/admin-badges/show.jsindex fdb7204d527..caa4f632694 100644--- a/app/assets/javascripts/admin/addon/controllers/admin-badges/show.js+++ b/app/assets/javascripts/admin/addon/controllers/admin-badges/show.js@@ -131,7 +131,7 @@ export default class AdminBadgesShowController extends Controller {}@action- validateForm(data, { addError }) {+ validateForm(data, { addError, removeError }) {if (!data.icon && !data.image_url) {addError("icon", {title: "Icon",@@ -141,6 +141,9 @@ export default class AdminBadgesShowController extends Controller {title: "Image",message: I18n.t("admin.badges.icon_or_image"),});+ } else {+ removeError("image_url");+ removeError("icon");}}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.gjsindex 124e70eb173..9abf212e077 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@@ -43,6 +43,7 @@ class FKForm extends Component {submit: this.onSubmit,reset: this.onReset,addError: this.addError,+ removeError: this.removeError,});this.router.on("routeWillChange", this.checkIsDirty);@@ -95,6 +96,11 @@ class FKForm extends Component {});}+ @action+ removeError(name) {+ this.formData.removeError(name);+ }+@actionasync addItemToCollection(name, value = {}) {const current = this.formData.get(name) ?? [];@@ -221,6 +227,7 @@ class FKForm extends Component {await this.args.validate?.(this.formData.draftData, {addError: this.addError,+ removeError: this.removeError,});} finally {this.isValidating = false;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.gjsindex 52784b3e06e..d030dfc9cae 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@@ -237,4 +237,31 @@ module("Integration | Component | FormKit | Form", function (hooks) {assert.dom(".foo").hasText("2");assert.dom(".bar").hasText("2");});++ test("reset virtual errors", async function (assert) {+ let validatedOnce = false;+ const validate = async (data, { removeError, addError }) => {+ if (!validatedOnce) {+ addError("foo", { title: "Foo", message: "error" });++ validatedOnce = true;+ } else {+ removeError("foo");+ }+ };++ await render(<template>+ <Form @validate={{validate}} as |form|>+ <form.Submit />+ </Form>+ </template>);++ await formKit().submit();++ assert.form().hasErrors({ foo: "error" });++ await formKit().submit();++ assert.form().hasNoErrors();+ });});