With the date field, can you restrict entries to the drop down option (eg not allow users to type their own value)?. If yes, how can it be done?
I also notice that you can enter invalid dates (eg 32/13/2010). Is there a way to stop invalid date entry?
Any help would be appreciated.
Views
Replies
Total Likes
With the date field, can you restrict entries to the drop down option (eg not allow users to type their own value)?. If yes, how can it be done?
Do you want to initialize the date and then prevent modification? If so, initialize the date and make the objected protected or read-only. For example, to initialize to the current date in the format MM/DD/YYYY
// form1.page1.currentDate::initialize - (FormCalc, client)
$.rawValue = Num2Date(Date(), "MM/DD/YYYY")
I also notice that you can enter invalid dates (eg 32/13/2010). Is there a way to stop invalid date entry?
If you add the validation pattern 'date{MM/DD/YYYY}' to date field you can influence the date entered. For a more hands-on approach you could add some script to the exit event such as
// form1.page1.currentDate::exit - (JavaScript, client)
var dateStr = this.formattedValue;
var regExp = /^\d{1,2}\/\d{1,2}\/d{4}$/;
if (!regExp.test(dateStr)) {
xfa.host.messageBox("Please enter the date in the format MM/DD/YYYY.");
}
While this script only validates the pattern, it could be enhanced to parse the month, day, and year for valid ranges.
Steve
Views
Replies
Total Likes
Hi Steve,
Thanks for the response.
Regards,
Jon
Date: Tue, 16 Mar 2010 14:33:36 -0600
From: forums@adobe.com
To: cazulu3@hotmail.com
With the date field, can you restrict entries to the drop down option (eg not allow users to type their own value)?. If yes, how can it be done?
Do you want to initialize the date and then prevent modification? If so, initialize the date and make the objected protected or read-only. For example, to initialize to the current date in the format MM/DD/YYYY
// form1.page1.currentDate::initialize - (FormCalc, client)
$.rawValue = Num2Date(Date(), "MM/DD/YYYY")
I also notice that you can enter invalid dates (eg 32/13/2010). Is there a way to stop invalid date entry?
If you add the validation pattern 'date{MM/DD/YYYY}' to date field you can influence the date entered. For a more hands-on approach you could add some script to the exit event such as
// form1.page1.currentDate::exit - (JavaScript, client)
var dateStr = this.formattedValue;
var regExp = /^\d{1,2}\/\d{1,2}\/d$/;
if (!regExp.test(dateStr)) {
xfa.host.messageBox("Please enter the date in the format MM/DD/YYYY.");
}
While this script only validates the pattern, it could be enhanced to parse the month, day, and year for valid ranges.
Steve
>
Views
Replies
Total Likes
Hi Steve,
I try to use your script but still I am getting a error(Incorect entered value) even if I enter the correct date pattern as MM/DD/YYYY!
Here are the setting for the date field:
For the date field validation patern I have enter:date{MM/DD/YYYY}
Validation script message checked
Validation pattern message Uncheck.
form1.#subform[0].currentDate::exit - (JavaScript, client)
var
dateStr = this.formattedValue;
var
regExp = /^\d{1,2}\/\d{1,2}\/d{4}$/;
if
(!regExp.test(dateStr)) {
xfa.host.messageBox("Please enter the date in the format MM/DD/YYYY.");
}
What I am doing wrong?
Thanks Steve
Views
Replies
Total Likes
Two things I did to fix this..
1) I changed the patterns like
Display: date{MMMM D, YYYY} // You can have any display pattern based on your need.
Edit: date{MM/DD/YYYY} // This is more important because this is the format user types in
Validation: //I removed the pattern for Validation because I am using JavaScript to validate the field input.
2) Changed the script a little to make it work.The code is still in the Exit event of the field.
var dateStr = this.editValue; //Instead of taking the this.formattedValue which gives the Display format, I took the Edit Value.
//var regExp = /^\d{1,2}\/\d{1,2}\/d{4}$/;
var regExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/; //Changed the reg expression a bit to make it work.
if(!regExp.test(dateStr)){
xfa.host.messageBox("Please enter the date in the format MM/DD/YYYY.");
xfa.host.setFocus(this); //Setting the focus to the same field.
}
Thanks
Srini
Views
Replies
Total Likes
Srini thanks for all your
help!
One more question, what will be the: var regExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/;
in case of MM/DD/YY date format?
Thanks
Views
Replies
Total Likes
For the date format of MM/DD/YY you need to do the following..
Edit Pattern for the Date Field: date{M/D/YY}
and Reg Expression will be
var regExp = /^\d{1,2}(\/)\d{1,2}\1\d{2}$/;
Thanks
Srini
Views
Replies
Total Likes