FIX: ensures default required validator handles 0 (#28686)
Prior to this fix `0` would be erroring as non-existing and would raise the required error.
This commit is contained in:
parent
c180d1db1e
commit
b771d3173f
|
@ -1,3 +1,4 @@
|
||||||
|
import { isBlank } from "@ember/utils";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
|
||||||
export default class Validator {
|
export default class Validator {
|
||||||
|
@ -114,7 +115,7 @@ export default class Validator {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!value) {
|
if (isBlank(value)) {
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,5 +267,10 @@ module("Unit | Lib | FormKit | Validator", function (hooks) {
|
||||||
[I18n.t("form_kit.errors.required")],
|
[I18n.t("form_kit.errors.required")],
|
||||||
"it returns an error when the value is undefined"
|
"it returns an error when the value is undefined"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
errors = await new Validator(0, {
|
||||||
|
required: {},
|
||||||
|
}).validate("xxx");
|
||||||
|
assert.deepEqual(errors, [], "it returns no error when the value is 0");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue