How to select only future date in date field using onsubmit client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 03:32 AM
Hi Team,
I have date field called return date. In that date field I need to select only present and future dates.
I can achieve this using ui policy, but I want to using client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 03:36 AM - edited 05-26-2023 03:37 AM
Hi @sriram7
You can use below on change client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var selectedDateNum = getDateFromFormat(newValue,g_user_date_time_format);
var today_date = new Date();
var today_dateStr = formatDate(today_date, g_user_date_time_format);
var todayDateNum = getDateFromFormat(today_dateStr, g_user_date_time_format);
if(selectedDateNum < todayDateNum) {
g_form.addErrorMessage("Selected date cannot be less than today's date");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 03:43 AM
I want to populate error message in when i am submitting catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 03:50 AM - edited 05-26-2023 03:55 AM
@sriram7 ,
You can create a on submit client script in that case with below code
function onSubmit(){
var dateVal=g_form.getValue('your date field');
var selectedDateNum = getDateFromFormat(dateVal ,g_user_date_time_format);
var today_date = new Date();
var today_dateStr = formatDate(today_date, g_user_date_time_format);
var todayDateNum = getDateFromFormat(today_dateStr, g_user_date_time_format);
if(selectedDateNum < todayDateNum) {
g_form.addErrorMessage("Selected date cannot be less than today's date");
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 03:56 AM