Hi Guys,
How to compare two dates in Freedom UI and display warning if first date is greater than second date in Freedom UI.
Thank you!
Like
You can use this example for date validation in the page handler code
//----------- DATE VALIDATION --------//
request: "crt.HandleViewModelAttributeChangeRequest",
handler: async (request, next) => {
// ------------Get the selected date values--------//
var dateFrom = await request.$context.DateTimeAttribute_6jtq65k;
var dateTo = await request.$context.DateTimeAttribute_vg9eydm;
// Check if dateFrom and dateTo values are valid
if (!dateFrom || !dateTo) {
return;
}
//------Convert the date values to JavaScript Date objects---------//
var jsDateFrom = new Date(dateFrom);
var jsDateTo = new Date(dateTo);
//---------Check the date values and display an error message-----------//
if (jsDateTo < jsDateFrom) {
var errorMessage = "Please choose a different 'dateTo' value. It should be greater than 'dateFrom'.";
Terrasoft.utils.showMessage({
caption: errorMessage,
message: errorMessage,
buttons: ["ok"],
defaultButton: 0,
style: Terrasoft.MessageBoxStyles.RED
});
request.$context.DateTimeAttribute_vg9eydm = null;
return;
}