Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

How to set a conditional date field value

Avatar

Level 3

Hello,

I've been trying to figure out how to set a date field to a specific value based on a conditional field.

I have a radio button with two options (yes & no). So, I want the date field to take on the value of "Aug 19, 2014" if the option "yes" is selected. Otherwise just allow the user to pick the date....

Thank you!!!

4 Replies

Avatar

Level 10

If you click yes just enter DateField.rawValue = "dd/mm/yy"; //the display pattern of "Aug 19,2014" should work on itself

also you probably want to put the field readOnly - >  DateField.access = "readOnly";

if you click no just enter DateField.rawValue = "";

also DateField.access = "open";

Avatar

Level 3

Thank you for your suggestion. I have already tried that but the issue with doing it that way is that the date field does not "like" the way the data is assigned to it. It gives me an error when I select "yes" that says "The value I entered is invalid". I can choose to ignore it and it does place the text as I put it in the code (format does not apply). However, it seems that replacing "plain text" into a date field is not 100% compatible...

Avatar

Level 10

Use FormCalc script language

DateTimeField1.rawValue = Num2Date(Date2Num("2014-01-25", "YYYY-MM-DD"))

Avatar

Level 3

Thanks again... I guess I failed to mention that I have two date fields and they are actually calculated (the difference between one another)... So, the date as it displays with your code "DateTimeField1.rawValue = Num2Date(Date2Num("2014-01-25", "YYYY-MM-DD"))" loses its numerical value. Hence, the numerical value of Aug 19, 2014 (41869) is not "behind the scenes" to be calculated as oposed to when a date is picked using the picker.

Also, I already have some JavaScript code on the change event of the radio button... Is there any way to make this code work in Javascript?

Thanks a billion!!!!