120 lines
3.2 KiB
JavaScript
120 lines
3.2 KiB
JavaScript
/* eslint-disable */
|
|
///////////////////////////////
|
|
// GZVALIDATE
|
|
//
|
|
// provides form validation services
|
|
// All locale keys for validation *MUST* be fetched prior to this being used as it assumes all keys are fetched first
|
|
// Add any new keys used to the block in locale.js=>commonKeysEditForm
|
|
|
|
import dayjs from "dayjs";
|
|
import locale from "./locale";
|
|
import _ from "../libs/lodash.min.js";
|
|
|
|
function isEmpty(o) {
|
|
if (typeof o == "number" && o == 0) {
|
|
return false;
|
|
}
|
|
return !o;
|
|
}
|
|
|
|
export default {
|
|
/*
|
|
ctrl.$refs[ref].value
|
|
0
|
|
ctrl.$refs[ref].label
|
|
"Count"
|
|
ctrl.$refs[ref].initialValue
|
|
*/
|
|
///////////////////////////////
|
|
// REQUIRED
|
|
// Required(ltkey, value) {
|
|
// if (!_.isEmpty(value)) {
|
|
// return false;
|
|
// }
|
|
// //get the localized rule text
|
|
// // "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}",
|
|
// var err = locale.get("ErrorRequiredFieldEmpty");
|
|
// var fieldName = locale.get(ltkey);
|
|
// err = _.replace(err, "{0}", fieldName);
|
|
// //lodash replace only replaces first instance so need to do it twice
|
|
// err = _.replace(err, "{0}", fieldName);
|
|
// return err;
|
|
// },
|
|
Required(v, ref) {HERE DID THIS METHOD OVER TO NEW WAY USING REF, NOW TO DO THE REST
|
|
var ctrl = v.$refs[ref];
|
|
if (isEmpty(ctrl)) {
|
|
return false;
|
|
}
|
|
|
|
var value = ctrl.value;
|
|
if (!isEmpty(value)) {
|
|
return false;
|
|
}
|
|
//get the localized rule text
|
|
// "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}",
|
|
var err = locale.get("ErrorRequiredFieldEmpty");
|
|
var fieldName = ctrl.label;
|
|
err = _.replace(err, "{0}", fieldName);
|
|
//lodash replace only replaces first instance so need to do it twice
|
|
err = _.replace(err, "{0}", fieldName);
|
|
return err;
|
|
},
|
|
///////////////////////////////
|
|
// MAXLENGTH
|
|
MaxLength(ltkey, value, max) {
|
|
if (_.isEmpty(value)) {
|
|
return false;
|
|
}
|
|
|
|
if (value.length > max) {
|
|
//get the localized rule text
|
|
// "ErrorFieldLengthExceeded": "{0} can not exceed {1} characters.",
|
|
var err = locale.get("ErrorFieldLengthExceeded");
|
|
var fieldName = locale.get(ltkey);
|
|
err = _.replace(err, "{0}", fieldName);
|
|
err = _.replace(err, "{1}", max);
|
|
return err;
|
|
} else {
|
|
return false;
|
|
}
|
|
},
|
|
///////////////////////////////
|
|
// MAX 255
|
|
Max255(ltkey, value) {
|
|
return this.MaxLength(ltkey, value, 255);
|
|
},
|
|
///////////////////////////////
|
|
// AFTER
|
|
After(startDate, endDate) {
|
|
if (_.isEmpty(startDate)) {
|
|
return false;
|
|
}
|
|
if (_.isEmpty(endDate)) {
|
|
return false;
|
|
}
|
|
|
|
startDate = dayjs(startDate);
|
|
endDate = dayjs(endDate);
|
|
|
|
// if either is not valid.
|
|
if (!startDate || !endDate) {
|
|
return false;
|
|
}
|
|
|
|
if (startDate.isAfter(endDate)) {
|
|
// "ErrorStartDateAfterEndDate": "Start date must be earlier than stop / end date",
|
|
var err = locale.get("ErrorStartDateAfterEndDate");
|
|
return err;
|
|
} else {
|
|
return false;
|
|
}
|
|
},
|
|
///////////////////////////////
|
|
// TEST
|
|
Test(ctrl, ref) {
|
|
var v = ctrl;
|
|
return false;
|
|
// return this.MaxLength(ltkey, value, 255);
|
|
}
|
|
};
|