start date and end date validation
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2024 08:34 AM
I have two fields in a delegate form starts and ends, when the start date and end date are equal and when the end date is less than the start date it should show an error message. I'm using the below onchange client script, the script is working only when the end date is less than the start date but it is not showing any error when the start date and end are the same.
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var selectedStartDate = g_form.getValue("starts");
if (isLoading || newValue === '' || selectedStartDate === '') {
return;
}
var selectedEndDate = new Date(newValue).getTime();
if (new Date(selectedStartDate) > selectedEndDate) {
g_form.setValue("ends", ' ');
g_form.showFieldMsg('ends', "The End Date should not be before the Start Date.", 'error');
} else if(new Date(selectedStartDate) === selectedEndDate){
g_form.setValue("ends", ' ');
g_form.showFieldMsg('ends', "The End Date should not be same as the Start Date.", 'error');
}
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2024 08:58 AM
Since these are date/time fields, the values pictured aren't equal. I would try the low-code scripted UI Policy approach: