on 12-01-2015 4:09 PM
Hello
I don't have a lot of experience writing javascript of an interactive Form and I need to validate the date entered by the user is > than tomorrow's date. This date is in a table so I wrote the code in the validate event of the field. I don't see the error message even if I write a date in the past. Here is the code:
data.Sect.Action.Action.Row1.dueDate::validate - (JavaScript, client)
var todayDate = new Date();
var newDate = this.rawValue;
// define 1 day in milliseconds
var oneDay = 1 * 24 * 60 * 60 * 1000;
// add 1 day to the today's date
var tomorrowDate = todayDate.getTime() + oneDay;
if(newDate < tomorrowDate)
{
xfa.host.messageBox("Please, do not write date in the past");
this.rawValue = tomorrowDate;
}
Could you please help me?
Thank in advance!
Marie-Josée
Hi Marie,
There are couple of things to consider in your code.
The date function gives a date in a date time format.
And your field on form not sure what format is it set to.
I have the below script, use "nextDay" thats in DD/MM/YYYY format and compare it with your user selected field. that should work.
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var tmp = dd+2;// (For the 3rd day);
var yyyy = today.getFullYear();
if(dd<10){
dd='0'+dd
}
if(mm<10){
mm='0'+mm
}
if(tmp<10){
tmp='0'+tmp
}
var formattedDate = dd+'/'+mm+'/'+yyyy;
var nextDay = tmp +'/'+mm+'/'+yyyy;
xfa.host.messageBox("today = "+today );
xfa.host.messageBox("ftdDate = "+formattedDate );
xfa.host.messageBox("nextDay = "+nextDay );
I had the alert messages for you only to test the script.
Cheers,
Sai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply I was able to solve it using this code
var tomorrowDate = new Date();
tomorrowDate.setDate(tomorrowDate.getDate() + 1);
var formatTomorrowDate = util.printd("yyyy-mm-dd",new Date(tomorrowDate));
var newDate = this.rawValue;
if(newDate < formatTomorrowDate)
{
xfa.host.messagebox("Please enter a valid date");
this.rawValue = formatTomorrowDate;
xfa.host.setFocus(this);
}
Regards,
Marie-Josée
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.