Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

  1.  
    I have a date field. I want to fix it so the the person filling out the field can't select a date prior to "TODAY".
    • CommentAuthordbuschho
    • CommentTimeAug 19th 2010
     
    Hello Martin,

    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;
    }


    setFuture(25);
    </script>

    Happy to help further,
    FA Support.
  2.  
    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?
    • CommentAuthordbuschho
    • CommentTimeAug 19th 2010
     
    Hello Martin,

    You can add a
    cfg.maxdate= Date;

    option to the code above, after where mindate is. You'll need to extend the code to match the proper range however.
  3.  
    Can you show me? I'm not quite understanding what you have in mind. Thanks.
  4.  
    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;
    }


    setFuture(0, 10);
    </script>
    • CommentAuthordbuschho
    • CommentTimeAug 19th 2010
     
    Sure thing, here you go:

    <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;
    }

    setRange(3,30);
    </script>
  5.  
    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;
    }


    setFuture(0, -1);
    </script>

    but I think I did it wrong.
    • CommentAuthordbuschho
    • CommentTimeAug 19th 2010
     
    <script>
    function setRange(from_days,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;

    if(from_days){
    var a = new Date();
    a.setDate(a.getDate()+from_days);
    cfg.mindate= a;
    cfg.pagedate=a;
    }

    if(to_days){
    var b = new Date();
    b.setDate(b.getDate()+to_days)
    cfg.maxdate= b;
    }

    }

    setRange(0,null);
    </script>

    should do it I think. Note, I don't believe the inequality operator from excel '<>' is valid in javascript.
  6.  
    Just tested it, I think that's got it. Thanks!
  7.  
    This would be a nice feature on the GUI if it could be added.
    • CommentAuthordbuschho
    • CommentTimeAug 19th 2010
     
    Feel free to put it on the uservoice page, Martin. If there's demand, I'm sure Cedric will consider it.
  8.  
    I did think of something - What if there is more that one calendar in the form? Will this script affect all the calendars in the form the same way?
    • CommentAuthordbuschho
    • CommentTimeAug 19th 2010
     
    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.
  9.  
    hmmm, this would be a problem then. I have several forms where the above script if used would break them.