Include this code in your custom code block, replacing setFuture(25) with the number of days into the future you'd like the minimum date to be, such as setFuture(0).
<script> function setFuture(days){ var a = new Date(); a.setDate(a.getDate()+days); // Calendar if(!wFORMS.helpers.calendar) { wFORMS.helpers.calendar = {}; } if(!wFORMS.helpers.calendar.locale) { wFORMS.helpers.calendar.locale = {}; } var cfg = wFORMS.helpers.calendar.locale; cfg.mindate= a; cfg.pagedate=a; }
This is great. I do have one other question. Is it possible to also have a max date also? For example, I may want to have the number of days in the future be 3 so I would set setFuture() to setFuture(3). However, I may also want to not let them go past 30 days. So, saying that, I would only want them to select a date between 3 days out and 30 days out. Is this possible?
I think you mean this, but this isn't tested <script> function setFuture(days, end){ var a = new Date(); var b = new Date(); a.setDate(a.getDate()+days); b.setDate(b.getDate()+end); // Calendar if(!wFORMS.helpers.calendar) { wFORMS.helpers.calendar = {}; } if(!wFORMS.helpers.calendar.locale) { wFORMS.helpers.calendar.locale = {}; } var cfg = wFORMS.helpers.calendar.locale; cfg.mindate= a; cfg.maxdate= b; cfg.pagedate=a; }
<script> function setRange(from_days,to_days){ var a = new Date(); a.setDate(a.getDate()+from_days); var b = new Date(); b.setDate(b.getDate()+to_days) // Calendar if(!wFORMS.helpers.calendar) { wFORMS.helpers.calendar = {}; } if(!wFORMS.helpers.calendar.locale) { wFORMS.helpers.calendar.locale = {}; } var cfg = wFORMS.helpers.calendar.locale; cfg.mindate= a; cfg.maxdate= b; cfg.pagedate=a; }
OK, what I posted works, but how would I fix it so if I wanted to disable either the start date or the end date without using a different script for each one?
I'm trying this: <script> function setFuture(days, end){ var a = new Date(); var b = new Date(); if days <> -1 {a.setDate(a.getDate()+days);} if end <> -1 {b.setDate(b.getDate()+end);} // Calendar if(!wFORMS.helpers.calendar) { wFORMS.helpers.calendar = {}; } if(!wFORMS.helpers.calendar.locale) { wFORMS.helpers.calendar.locale = {}; } var cfg = wFORMS.helpers.calendar.locale; cfg.mindate= a; cfg.maxdate= b; cfg.pagedate=a; }
Yes. There is only ever one calendar GUI that get's shared amongst all the date field instances on the form. Any change to the calendar affects all of them.