diff --git a/app/assets/javascripts/discourse/app/form-kit/lib/validator.js b/app/assets/javascripts/discourse/app/form-kit/lib/validator.js
index 20426272db7..817f43e702a 100644
--- a/app/assets/javascripts/discourse/app/form-kit/lib/validator.js
+++ b/app/assets/javascripts/discourse/app/form-kit/lib/validator.js
@@ -104,7 +104,7 @@ export default class Validator {
}
break;
case "input-number":
- if (!value || typeof value === "undefined" || isNaN(Number(value))) {
+ if ((!value && value !== 0) || isNaN(Number(value))) {
error = true;
}
break;
diff --git a/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-number-test.gjs
similarity index 59%
rename from app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-test.gjs
rename to app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-number-test.gjs
index e6c7367430a..5b645f1af1f 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-number-test.gjs
@@ -1,38 +1,15 @@
-import { render } from "@ember/test-helpers";
+import { fillIn, render } from "@ember/test-helpers";
import { module, test } from "qunit";
import Form from "discourse/components/form";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import formKit from "discourse/tests/helpers/form-kit-helper";
module(
- "Integration | Component | FormKit | Controls | Input",
+ "Integration | Component | FormKit | Controls | Input | Number",
function (hooks) {
setupRenderingTest(hooks);
- test("default", async function (assert) {
- let data = { foo: "" };
- const mutateData = (x) => (data = x);
-
- await render(
-
-
-
-
- );
-
- assert.form().field("foo").hasValue("");
-
- await formKit().field("foo").fillIn("bar");
-
- assert.form().field("foo").hasValue("bar");
-
- await formKit().submit();
-
- assert.deepEqual(data.foo, "bar");
- });
-
- test("@type", async function (assert) {
+ test("@type=number", async function (assert) {
let data = { foo: "" };
const mutateData = (x) => (data = x);
@@ -54,5 +31,29 @@ module(
assert.deepEqual(data.foo, 1);
});
+
+ test("validation of required", async function (assert) {
+ await render(
+
+
+
+
+ );
+
+ await formKit().submit();
+
+ assert.form().hasErrors({ foo: ["Required"] });
+ assert.form().field("foo").hasError("Required");
+
+ await fillIn("input", "0");
+ await formKit().submit();
+ assert.form().field("foo").hasNoError();
+ });
}
);
diff --git a/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-text-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-text-test.gjs
new file mode 100644
index 00000000000..1bf1df45e94
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/integration/components/form-kit/controls/input-text-test.gjs
@@ -0,0 +1,35 @@
+import { render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import Form from "discourse/components/form";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import formKit from "discourse/tests/helpers/form-kit-helper";
+
+module(
+ "Integration | Component | FormKit | Controls | Input | Text",
+ function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("default", async function (assert) {
+ let data = { foo: "" };
+ const mutateData = (x) => (data = x);
+
+ await render(
+
+
+
+
+ );
+
+ assert.form().field("foo").hasValue("");
+
+ await formKit().field("foo").fillIn("bar");
+
+ assert.form().field("foo").hasValue("bar");
+
+ await formKit().submit();
+
+ assert.deepEqual(data.foo, "bar");
+ });
+ }
+);