Skip to content

Commit

Permalink
Merge pull request #249 from digi-serve/ben/DisableFutureDate
Browse files Browse the repository at this point in the history
Ben/disable future date
  • Loading branch information
wirachot authored Sep 13, 2024
2 parents cce4c22 + 518bc8b commit b51dd24
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions dataFields/ABFieldDateCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

const ABField = require("../../platform/dataFields/ABField");

function L(key, altText) {
// TODO:
return altText; // AD.lang.label.getLabel(key) || altText;
}
/*function L(key, altText) {
// TODO:git
// return altText; // AD.lang.label.getLabel(key) || altText;
}*/

const ABFieldDateDefaults = {
key: "date",
Expand Down Expand Up @@ -158,6 +158,10 @@ module.exports = class ABFieldDateCore extends ABField {
*/
isValidData(data, validator) {
super.isValidData(data, validator);
var L = this.AB.Label();

const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);

if (data[this.columnName]) {
let value = data[this.columnName];
Expand Down Expand Up @@ -301,6 +305,30 @@ module.exports = class ABFieldDateCore extends ABField {
L("Should before or equal {0}", [startDateDisplay])
);
break;
case "lessCurrentDate":
isValid =
value.getTime &&
value.getTime() < currentDate.getTime();
if (!isValid)
validator.addError(
this.columnName,
L("Should before {0}", [
this.getDateDisplay(currentDate),
])
);
break;
case "lessEqualCurrentDate":
isValid =
value.getTime &&
value.getTime() <= currentDate.getTime();
if (!isValid)
validator.addError(
this.columnName,
L("Should before or equal {0}", [
this.getDateDisplay(currentDate),
])
);
break;
}
}

Expand Down

0 comments on commit b51dd24

Please sign in to comment.