fix: empty string validation if required is set (#9476)
This commit is contained in:
parent
31cac9f85f
commit
eed6ad9166
|
|
@ -45,6 +45,10 @@ describe("Checkbox Group Widget Functionality", function() {
|
|||
"not.have.value",
|
||||
"test4",
|
||||
);
|
||||
cy.get(formWidgetsPage.deleteradiovalue)
|
||||
.eq(2)
|
||||
.click({ force: true });
|
||||
cy.wait(200);
|
||||
/**
|
||||
* @param{Show Alert} Css for InputChange
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -74,8 +74,11 @@ describe("Validate Validators", () => {
|
|||
parsed: "123",
|
||||
},
|
||||
{
|
||||
isValid: true,
|
||||
parsed: "",
|
||||
isValid: false,
|
||||
parsed: "abc",
|
||||
messages: [
|
||||
`${WIDGET_TYPE_VALIDATION_ERROR} string ( abc | 123 | mno | test )`,
|
||||
],
|
||||
},
|
||||
];
|
||||
inputs.forEach((input, index) => {
|
||||
|
|
@ -101,10 +104,7 @@ describe("Validate Validators", () => {
|
|||
];
|
||||
const expected = [
|
||||
{
|
||||
isValid: false,
|
||||
messages: [
|
||||
"This value does not evaluate to type (http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&\\/=]*)",
|
||||
],
|
||||
isValid: true,
|
||||
parsed: "https://www.appsmith.com",
|
||||
},
|
||||
{
|
||||
|
|
@ -152,8 +152,7 @@ describe("Validate Validators", () => {
|
|||
];
|
||||
const expected = [
|
||||
{
|
||||
isValid: false,
|
||||
messages: ["This value does not evaluate to type URL"],
|
||||
isValid: true,
|
||||
parsed: "https://www.appsmith.com",
|
||||
},
|
||||
{
|
||||
|
|
@ -192,7 +191,7 @@ describe("Validate Validators", () => {
|
|||
const expected = [
|
||||
{
|
||||
isValid: true,
|
||||
parsed: "",
|
||||
parsed: "abc",
|
||||
},
|
||||
];
|
||||
inputs.forEach((input, index) => {
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ export const VALIDATORS: Record<ValidationTypes, Validator> = {
|
|||
value: unknown,
|
||||
props: Record<string, unknown>,
|
||||
): ValidationResponse => {
|
||||
if (value === undefined || value === null) {
|
||||
if (value === undefined || value === null || value === "") {
|
||||
if (config.params && config.params.required) {
|
||||
return {
|
||||
isValid: false,
|
||||
|
|
@ -342,9 +342,7 @@ export const VALIDATORS: Record<ValidationTypes, Validator> = {
|
|||
return stringValidationError;
|
||||
}
|
||||
}
|
||||
// If the value is an empty string we skip
|
||||
// as we do not mark the field as an error
|
||||
if (config.params?.allowedValues && value !== "") {
|
||||
if (config.params?.allowedValues) {
|
||||
if (!config.params?.allowedValues.includes((parsed as string).trim())) {
|
||||
return {
|
||||
parsed: config.params?.default || "",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user