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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Restricting a Date Field - 2 Weeks from Today

Not applicable
Hi,



I am working on an Order Form. There is a field called 'OrderDate' which is today's current date. There is another field called 'RequiredDate' which is the date I want restricted. Currently I have this field set with a Value Type of "User Entered - Required".



I want to also script the field so that clients can ONLY enter a date that is at least 2 weeks in the Future or more. Any help would be greatly appreciated.



Thanks,
1 Reply
Niall_O_Donovan
Level 10
Level 10
Hi Audrey,



This may not be the prettiest solution, but I did get it to work.



First create two visible date fields "order_date" and "required_date".



Then set up two hidden fields "order_date_num" [numeric field] and "required_date_check" [date field].



The "order_date" field does not have any script.



The "order_date_num" field has the following Formcalc in the calculate event (this converts the date to a number):



b $ = Date2Num(order_date.rawValue, "YYYY-MM-DD", "en_IE")



The "required_date_check" has the following Formcalc in the calculate event (this adds 14 days to the number [if the order_date is not empty] and converts it back to a date):



b if (HasValue(order_date_num)) then



b $ = Num2Date(order_date_num.rawValue + 14, "YYYY-MM-DD", "en_IE")



b else $ = null



b endif



The "required_date" field has the same Formcalc in the calculate event (this auto populates the Required Date field to 14 days time, prompting the user):



b if (HasValue(order_date_num)) then



b $ = Num2Date(order_date_num.rawValue + 14, "YYYY-MM-DD", "en_IE")



b else $ = null



b endif



I set the "required_date" field to calculated, but user can overide, so the last script is needed to prevent the user setting a date sooner than 14 days. The Javascript is in the "required_date" exit event (this checks the value at exit to the "required_date_check" valua and if less than 14 days, throws up a warning and resets the date to 14 days):



b if (this.rawValue < required_date_check.rawValue)



b {



b app.alert({



b cMsg: "WARNING - Check Required Date.\n\n The required date must be b at least two weeks after the Order Date.",



b cTitle: "YOUR ORGANISATION",



b nIcon: 1, nType: 0



b });



b this.rawValue = required_date_check.rawValue;



b }



Hope this helps! It may be possible to achieve the same effect in less steps, but that is beyond me.



Regards,



Niall