fix: Update date ISO string validations (#11399)
This commit is contained in:
parent
c30f072c84
commit
5dc5cff722
|
|
@ -105,6 +105,16 @@ describe("DatePicker Widget Property pane tests with js bindings", function() {
|
|||
cy.closePropertyPane();
|
||||
cy.assertDateFormat();
|
||||
});
|
||||
|
||||
it("Datepicker default date validation with js binding and default date with moment object", function() {
|
||||
cy.openPropertyPane("datepickerwidget2");
|
||||
cy.testJsontext("defaultdate", `{{moment("1/1/2012")}}`);
|
||||
cy.get(".t--widget-datepickerwidget2 .bp3-input").should(
|
||||
"contain.value",
|
||||
"01/01/2012 00:00",
|
||||
);
|
||||
});
|
||||
|
||||
it("Datepicker default date validation with js binding", function() {
|
||||
cy.PublishtheApp();
|
||||
// eslint-disable-next-line cypress/no-unnecessary-waiting
|
||||
|
|
|
|||
|
|
@ -778,32 +778,25 @@ export const VALIDATORS: Record<ValidationTypes, Validator> = {
|
|||
value: unknown,
|
||||
props: Record<string, unknown>,
|
||||
): ValidationResponse => {
|
||||
const invalidResponse = {
|
||||
isValid: false,
|
||||
parsed: config.params?.default,
|
||||
messages: [`Value does not match: ${getExpectedType(config)}`],
|
||||
};
|
||||
if (value === undefined || value === null || !isString(value)) {
|
||||
if (!config.params?.required) {
|
||||
return {
|
||||
isValid: true,
|
||||
parsed: value,
|
||||
};
|
||||
}
|
||||
return invalidResponse;
|
||||
}
|
||||
if (isString(value)) {
|
||||
if (value === "" && !config.params?.required) {
|
||||
return {
|
||||
isValid: true,
|
||||
parsed: config.params?.default,
|
||||
};
|
||||
} else if (value === "" && config.params?.required) {
|
||||
return invalidResponse;
|
||||
}
|
||||
let isValid = false;
|
||||
let parsed = value;
|
||||
let message = "";
|
||||
|
||||
if (!moment(value).isValid()) return invalidResponse;
|
||||
if (_.isNil(value) || value === "") {
|
||||
parsed = config.params?.default;
|
||||
|
||||
if (config.params?.required) {
|
||||
isValid = false;
|
||||
message = `Value does not match: ${getExpectedType(config)}`;
|
||||
} else {
|
||||
isValid = true;
|
||||
}
|
||||
} else if (typeof value === "object" && moment(value).isValid()) {
|
||||
//Date and moment object
|
||||
isValid = true;
|
||||
parsed = moment(value).toISOString(true);
|
||||
} else if (isString(value)) {
|
||||
//Date string
|
||||
if (
|
||||
value === moment(value).toISOString() ||
|
||||
value === moment(value).toISOString(true)
|
||||
|
|
@ -812,11 +805,29 @@ export const VALIDATORS: Record<ValidationTypes, Validator> = {
|
|||
isValid: true,
|
||||
parsed: value,
|
||||
};
|
||||
} else if (moment(value).isValid()) {
|
||||
isValid = true;
|
||||
parsed = moment(value).toISOString(true);
|
||||
} else {
|
||||
isValid = false;
|
||||
message = `Value does not match: ${getExpectedType(config)}`;
|
||||
parsed = config.params?.default;
|
||||
}
|
||||
if (moment(value).isValid())
|
||||
return { isValid: true, parsed: moment(value).toISOString(true) };
|
||||
} else {
|
||||
isValid = false;
|
||||
message = `Value does not match: ${getExpectedType(config)}`;
|
||||
}
|
||||
return invalidResponse;
|
||||
|
||||
const result: ValidationResponse = {
|
||||
isValid,
|
||||
parsed,
|
||||
};
|
||||
|
||||
if (message) {
|
||||
result.messages = [message];
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
[ValidationTypes.FUNCTION]: (
|
||||
config: ValidationConfig,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user