Expand my Community achievements bar.

START DATE should not lower than CURRENT/TODAYS DATE?

Avatar

Level 8

Hello

I put CONTRACT START DATE and CONTRACT END DATE fields on the form. These 2 objects (Date/Time objjects) i pulled them from Satndard tab of pallette and dropped on my layout page design, fine.

Now, am trying to put a validation that the START DATE should not lower than CURRENT/TODAYS DATE date, if so, i want to,

1 - Throw error message (either JavaScript - app.alert, FormCalc - xfa.host.messageBox)

2 - CLEARing the START DATE

Pls. help me by giving the either JavaScript code or FormCalc code, either one is fine but should be simpler (i heard FormCalc hadles DATES validations with simple/small code)

Thank you

8 Replies

Avatar

Level 10

To determine if the start date is lower than the current date you can eiter use FormCalc or JavaScript.

FormCalc already has several date/time functions which make it easier to handle.

This is a sample for the exit Event of your date field.

It checks if the field has a value, and if the date is before today's date.

If so, it will show a message and clear the field.

Avatar

Level 8

Sorry, its not working, i mean, i am (tested as a user) getting this error/message box for all kind of inputs (past date, todays date, future date selection), the field object is a DATE/TIME object dragged from STANDARD tab of pallettte.

I put your code in exit of that date field with FormClac

I knew you said, its sample, am newbie, by chance if you have time, pls. provide me all the code.

Any help?

By the way, how you guys are putting code with a lines back ground, bcz i want to put the same, but i did not see that formatting option (i saw bold. italic, font family, bulletts, but not this back ground for code)

Thank you

Avatar

Level 5

The code is correct but you need to put a display pattern on your date field which matches the one in the code (MM/DD/YYYY). You can do that under the Field Tab, Patterns Button and select Display. If you have to change it, you change it in both locations, otherwise Date2Num will return 0 all the time.

Avatar

Level 10

dohanlon is right, the pattern is the important factor.

There are manifold ways to display a date like todays date. 14.03.2012, 03/14/2012, 14-3-12, 14 Mar 2012 etc... .

The FormCalc script I used before tries to convert the displayed date of your start date field into a number.

Date2Num($.formattedValue, "MM/DD/YYYY") will return the value 40981 for taday's date, but only if the date is entered in the format "MM/DD/YYYY" (means 03/14/2012).

It can become very nasty to explain users how to enter the dates in the wanted format, so you can use edit and display patterns, to avoid this.

Here's a description, how to use multiple edit patterns in date fields, to allow a most flexible input.

http://thelivecycle.blogspot.com/2011/10/date-patterns.html

Avatar

Level 8

Thank you for your gr8 info.

Sorry i forgot to mention that my form is global (US and Europe - DD/MM/YYYY)...

Avatar

Level 8

Thank you for your gr8 info.

Sorry i forgot to mention that my form is global (US and Europe - DD/MM/YYYY)...

Yup, i will go thru the link.

Thank you