Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

prevent date in the past

rickstsx04
Level 3
Level 3

I am trying to prevent a date field from allowing a user to enter a date prior to the current date. How can this be done?

4 Replies
radzmar
Level 10
Level 10

Hi,

you can use a FormCalc script in the date fields exit event to inform the user an delete the invalid field data.


if (date2Num($.formattedValue, "DD.MM.YYYY") lt Date()) then


  if ($host.messageBox("You cannot select a date in the past", "invalid date", 0,0) eq 1) then


  $.rawValue = ""


  $host.setFocus(Ref($))


  endif


endif


mouslander
Level 7
Level 7

This works great. The pattern for the date field has to be set to whatever is in the script. I had my date field as MM/DD/YYYY and it would not work until I modified the formattedValue line to match the pattern for the field.

radzmar
Level 10
Level 10

Correct, the pattern in the script has to be the one you use to display your date.

In the US it's generally MM/DD/YYYY and in Germany it's DD.MM.YYYY

rickstsx04
Level 3
Level 3

Thank you for your help! Worked like a charm! Many thanks!