• Hi,

    On my website alegrefarm.com/contact, I’m using Gravity Forms plugin and I needed to block Sunday on one of my fields and inserted the script:

    <script>// no sundays
    gform.addFilter( ‘gform_datepicker_options_pre_init’, function( optionsObj, formId, fieldId ) {

    optionsObj.firstDay = 1;
    optionsObj.beforeShowDay = function(date) {
    var day = date.getDay();
    return [(day > 0), ”];
    };

    return optionsObj;
    });
    </script>

    It works, but unfortunately, I have two calendar fields and I don’t need to block sunday on both. On the first calendar field, Sunday does not need to be blocked (Field ID 9). Sundays need to be blocked only on the second calendar field (Field ID 25).

    Gravity Forms support gave me a link to:
    https://gist.github.com/richardW8k/515454542d1111e8c12c

    and told me to use the “if” statement. I don’t know what that means but they won’t help me any further.

    I tried this but it doesn’t work:

    <script>// no sundays
    gform.addFilter( ‘gform_datepicker_options_pre_init’, function( optionsObj, formId, fieldId ) {
    if (formId == 25)
    optionsObj.firstDay = 1;
    optionsObj.beforeShowDay = function(date) {
    var day = date.getDay();
    return [(day > 0), ”];
    };

    return optionsObj;
    });
    </script>

    Anyone have any idea what this script needs to be in order to achieve my goal of only blocking Sunday on the second calendar field (Field ID 25?) Thank you.

    Best Regards,

    Kelly

Viewing 1 replies (of 1 total)
  • I know this is a bit old, but I thought it should be answered. You need to select a formID and fieldID for separate field conditions. Your day > 0 return will work.

    Your code should look something like this:

    <script>
    gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
    if ( formId == 10 && fieldId == 9 ) {
    //Block Here for first calendar
    }
    return optionsObj;
    
    if ( formId == 10 && fieldId == 25 ) {
    //Block Here for second calendar
    }
    return optionsObj;
    </script>

    You can find additional details about about similar examples here:
    https://www.gravityhelp.com/documentation/article/gform_datepicker_options_pre_init/
    https://api.jqueryui.com/datepicker/

    This is my sample for only allowing mondays and tuesdays for form 4 on field 6 (a calendar).

    <script>
    gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
        if ( formId == 4 && fieldId == 6 ) {
            optionsObj.firstDay = 1;
            optionsObj.beforeShowDay = function(date) {
                var day = date.getDay();
                return [(day == 1 || day == 2)];
            };
        }
        return optionsObj;
    });
    </script>
Viewing 1 replies (of 1 total)
  • The topic ‘Gravity Forms – Blocking Day on Calendar Field Script’ is closed to new replies.