Good point. The problem here is that picking a date from the drop-down calendar will set the field to a date value with the YYYY-MM-DD format which makes things a little more complicated to verify.
If you keep the code as I had demonstrated it, the following line would always fail with a date in the YYYY-MM-DD format:
if (Date2Num($.rawValue, "MM/DD/YYYY") <= 0)
This is because $.rawValue is "2006-06-28", for example, as opposed to "06/28/2006".
The trick here is to use the field's
formatted value (its raw value formatted with its Display Pattern) in the Date2Num function as opposed to the field's
raw value. By setting the Display Pattern to "MM/DD/YYYY" and then using the following code,
if (Date2Num($.formattedValue, "MM/DD/YYYY") <= 0)
the YYYY-MM-DD value assigned by the drop-down calendar will automatically be formatted (transformed) into the MM/DD/YYYY format and the Date2Num function will succeed.
The last thing to do is ensure that the field's value is always stored in the MM/DD/YYYY format. You can do this simply by assigning the formatted value to the raw value when the Date2Num function succeeds:
$.rawValue = $.formattedValue
I've attached a second sample form (second version of the first one) which has the fix for using dates selected from the drop-down calendar. It also contains a slight adjustment to make sure that the script doesn't run when the field's value is empty (null):
if ($.isNull ne 1)
This avoids having the error message be displayed when the user simply tabs/clicks in and out of the date field without entering/picking a value.
Finally, this fix has the added benefit of fixing-up the value entered by the user if it doesn't entirely match the MM/DD/YYYY pattern where if the user enters "6/28/06", the value will automatically be adjusted to "06/28/2006". Entering "6-28-06", however, will still fail and cause the error message to be displayed.
Stefan
Adobe Systems