- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 05:23 PM
Hi Team,
Please find the below snippet i used to validate the date field to select only the current and future date.
But the problem is im unable to select the current date.
Please guide where i m wrong.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var today = new Date();
var dateMS = today.getTime();
var current_date = new Date();
current_date.setTime(dateMS);
var new_date = new Date(getDateFromFormat(newValue, g_user_date_time_format));
g_form.setValue('ftr_needed_by',formatDate(current_date,g_user_date_time_format));
if(new_date>=current_date)
{
// this is valid
}
else{
alert("selected date should be current date or future date");
g_form.setValue('axa_asia_ph_var_date_needed','');
}
}
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2016 03:38 AM
Hi,
Rather than client script use the following UI policy with the following condition :
Write following script :
function onCondition() {
g_form.setValue('date_of_joining', "'');
alert("Enter valid date");
}
Its simple and works in all the cases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 09:18 PM
Hi Smitha,
This OnChange client script would serve your purpose :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var currentDate = new Date();
var currentDateFormat = formatDate(currentDate, g_user_date_time_format); // get the user date format
var currentDateFinal = getDateFromFormat(currentDateFormat, g_user_date_time_format);//convert to the user date format
//alert(currentDateFinal);
//get duration
var duration = g_form.getValue('u_startdt');//get your variable field date
var durationFinal = getDateFromFormat(duration, g_user_date_time_format);//convert to the user date format
//alert(durationFinal);
var difference = durationFinal - currentDateFinal;
if (difference < 0) {
//flag++;
alert('You cannot select a date in the past.');
g_form.setValue('u_startdt', ''); //Replace u_startdt with your variable name
}
Please let me know if you have further queries.
Thanks,
Arnab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2016 02:55 AM
Hello Everyone,
I tried all the above scripts you provided .. but no luck.
It seems very simple but im unable to trigger-out the mistake.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var today = new Date();
var dateMS = today.getTime();
var current_date = new Date();
current_date.setTime(dateMS);
var selected_date = new Date(getDateFromFormat(newValue, g_user_date_format));
g_form.setValue('ftr_needed_by',formatDate(current_date,g_user_date_format));
alert(selected_date);
alert(current_date);
if(selected_date >= current_date)
{
//valid condition
}
else{
alert("selected date should be current date or future date");
g_form.setValue('axa_asia_ph_var_date_needed','');
}
}
Please can anyone correct the code above.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2016 02:59 AM
I found that getDateFromFormat function wasn't working for me. Which is why my code above does not use it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2016 03:23 AM
For what it's worth, my script was not intended to run as-is. You will need to modify it for your field(s) and remove the bits you don't need (e.g. start < end comparison.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2016 03:38 AM