Not signed in (Sign In)

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

    • CommentAuthorafrank
    • CommentTimeJul 28th 2011
     
    Wanted to know if there is any way to create custom date validation? I want to be able to specify that if a date is selected from the date dialogue box, that it must be x days after "today's" date - today would be a relative date and not a fixed date.

    Please let me know if this is possible.
    • CommentAuthordbuschho
    • CommentTimeJul 28th 2011
     
    Hello,

    Unfortunately there isn't an easy way to accomplish this. Here's the closest to an easiest way:
    1. Create a field on your form and mark it as 'validate-date with calendar popup'.
    2. Go to http://app.formassembly.com/forms/prefill_info/FORM_ID
    (where FORM_ID is the number of your form)
    3. Record the id for the field you just created.
    4. Paste this code into your custom code block (replacing tfa_FIELDID with the value from step 3, and DAYS with number of days in the future to limit by):
    <script>
    var elem = 'tfa_FIELDID';
    //Do not change below this line
    base2.DOM.Element.addEventListener(document,'DOMContentLoaded',function(){
    wFORMS.behaviors.validation.rules.isDateInTheFuture = { selector: "#"+elem, check: 'validateDateInTheFuture' }
    wFORMS.behaviors.validation.messages.isDateInTheFuture = "This date cannot more than DAYS in the future.";
    wFORMS.behaviors.validation.instance.prototype.validateDateInTheFuture = function(element, value) {
    var testDate = new Date(value);
    var today = new Date();
    today.setDate(today.getDate()+DAYS)
    return (testDate.getTime() < today.getTime());
    };
    });
    </script>
    • CommentAuthorafrank
    • CommentTimeJul 28th 2011
     
    Is the procedure the same if I want it to be "can't be less than DAYS in the future"?

    Also, can any of this be done on my basic subscription? I have the lowest level paid plan. Not sure if this is available in my subscription. Please let me know.

    Thank you for the quick response!
    • CommentAuthordbuschho
    • CommentTimeJul 28th 2011
     
    Ah, ok, then this is probably a better solution:

    Limit date selection to certain number of days after current:

    <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;
    }
    setFuture(15);
    </script>

    Which should force the calendar to not event let users select a date less than 15 days in the future.