Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed the custom rules to avoid conflicts #443

Open
wants to merge 1 commit into
base: release-2024-fall
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/components/mixins/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,28 @@ export default {
let data = this.validationData ? this.validationData : { [fieldName]: this.value };
let validationRules = "";

if (typeof this.validation !== "string" && this.validation.length) {
if (Array.isArray(this.validation)) {
let rules = [];

this.validation.forEach((configs) => {
if (!configs.value) {
return;
}
rules.push(configs.value);
const ruleValue = configs.value
.replace('after:', 'after_date:')
.replace('before:', 'before_date:')
.replace('after_or_equal:', 'after_or_equal_date:')
.replace('before_or_equal:', 'before_or_equal_date:');
rules.push(ruleValue);
});

validationRules = rules;
} else {
validationRules = this.validation;
validationRules = this.validation
.replace('after:', 'after_date:')
.replace('before:', 'before_date:')
.replace('after_or_equal:', 'after_or_equal_date:')
.replace('before_or_equal:', 'before_or_equal_date:');
}

let rules = {
Expand Down Expand Up @@ -172,7 +181,7 @@ export default {
);

Validator.register(
"after",
"after_date",
function (date, params) {
// checks if incoming 'params' is a date or a key reference.
let checkDate = moment(params);
Expand All @@ -185,11 +194,11 @@ export default {

return inputDate > afterDate;
},
"The :attribute must be after :after."
"The :attribute must be after :after_date."
);

Validator.register(
"after_or_equal",
"after_or_equal_date",
function (date, params) {
// checks if incoming 'params' is a date or a key reference.
let checkDate = moment(params);
Expand All @@ -202,11 +211,11 @@ export default {

return inputDate >= equalOrAfterDate;
},
"The :attribute must be equal or after :after_or_equal."
"The :attribute must be equal or after :after_or_equal_date."
);

Validator.register(
"before",
"before_date",
function (date, params) {
// checks if incoming 'params' is a date or a key reference.
let checkDate = moment(params);
Expand All @@ -219,11 +228,11 @@ export default {

return inputDate < beforeDate;
},
"The :attribute must be before :before."
"The :attribute must be before :before_date."
);

Validator.register(
"before_or_equal",
"before_or_equal_date",
function (date, params) {
// checks if incoming 'params' is a date or a key reference.
let checkDate = moment(params);
Expand All @@ -236,7 +245,7 @@ export default {

return inputDate <= beforeDate;
},
"The :attribute must be equal or before :before_or_equal."
"The :attribute must be equal or before :before_or_equal_date."
);

Validator.register(
Expand Down
Loading