hi team
I am unable to get output please send me sample one I am tried in 2 ways
please check the code once where I have made a mistake .send me one sample
code 1)
methods: {
setValidationConfig: function() {
// Calls the initialization of validators for the parent view model.
this.callParent(arguments);
// this.addColumnValidator("CreatedOn", this.DateOfBirthValidation);
},
DateOfBirthValidation: function(value1) {
var invalidMessage = "";
var isValid = true;
var number1 = value1 || this.get("UsrDateOfBirth");
var number2 = this.get("CreatedOn");
var nd1 = number1.substr(0, 2);
var nm1 = number1.substr(3, 2);
var ny1 = number1.substr(6, 4);
var cnumber1 = "";
cnumber1 = nm1 + "-" + nd1 + "-" + ny1;
//var today = new Date();
//var birthDate = new Date(cnumber);
var nd2 = number2.substr(0, 2);
var nm2 = number2.substr(3, 2);
var ny2 = number2.substr(6, 4);
var cnumber2 = "";
cnumber2 = nm2 + "-" + nd2 + "-" + ny2;
//day
var bd1 = number1.substr(0, 2);
bd1 = parseInt(bd1, bd1);
var bd2 = number2.substr(0, 2);
bd2 = parseInt(bd2, bd2);
var d = bd1 - bd2;
//year
var age = ny1 - ny2;
if ((age === 18)) {
isValid = true;
} else if (age < 18) {
isValid = false;
} else if (age > 18) {
isValid = true;
}
if (!isValid) {
invalidMessage = this.get("Resources.Strings.InvalidDOBFormat");
}
// Object which properties contain validation error messages.
// If the validation is successful, empty strings are returned to the object.
return {
invalidMessage: invalidMessage
};
},
code 2)
function calculateAge() {
var seldate = document.getElementById("childrenAge").value;
dt1 = new Date(); //today date
dt2 = new Date(seldate); //selected date
var age =diff_years(dt1, dt2);
if(age<18){
alert("please select date more than or equals to 18");
document.getElementById("childrenAge").value =""
}
}
function diff_years(dt1, dt2)
{
var diff =(dt2.getTime() - dt1.getTime()) / 1000;
diff /= (60 * 60 * 24);
return Math.abs(Math.round(diff/365.25));
}
Like
Hello manikanta,
The example of field validation is here:
https://academy.bpmonline.com/documents/technic-sdk/7-13/how-add-field-…
Please, check your DateOfBirthValidation function, it should not take an argument.
About your second code: we do not recommend to get values from the DOM, use attributes instead.
Please, check the links below:
Difference between two dates: https://stackoverflow.com/questions/3224834/get-difference-between-2-da…
How to debug client code:
https://academy.bpmonline.com/documents/technic-sdk/7-13/client-code-de…
Dates in JS:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Globa…
Best regards,
Alex