PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Custom configured datepicker not passing the validation

  1. bluantinoo
    Member

    Hello,
    I've customized the datepicker configuration to allow just future dates, no weekends or holidays.

    The configuration seeems to work fine, and you can have a look at the form here:
    http://www.teloaggiusto.io/riparazione-iphone/iphone-4/
    datepicker is in the second page of this multi-page form, at the beginning of the page.
    It's under a conditional logic: to see it you have to change the very first radio button to "Voglio fissare un'altra data".

    As you can see the calendar widget is working fine:
    you can select just future days, and no weekends or holidays.

    BUT for some reason I cannot figure out, if I try to choose a future date that is more than 15 days in the future, it won't pass the validation, it display the error as the field it's left empty.

    I'll paste here the code I use:

    1) in functions.php of my template I have this:

    add_action('wp_enqueue_scripts', 'enqueue_daterestrict_script', 10, 2);
    function enqueue_daterestrict_script() {
    		wp_enqueue_script('daterestrict_script', get_stylesheet_directory_uri() . '/js/datepicker-restrictions.js', array('jquery'));
    }

    2) then In the datepicker-restrictions.js file I have all this stuff:

    // array of year holidays [month, day]
     natDays = [
            [1, 1], [1, 6], [4, 25], [5, 1], [6, 2], [8, 15], [11, 1], [12, 8], [12, 25], [12, 26]
        ];
    
        function nationalDays(date) {
            for (i = 0; i < natDays.length; i++) {
                if (date.getMonth() == natDays[i][0] - 1
                && date.getDate() == natDays[i][1]) {
                    return [false, natDays[i][2] + '_day'];
                }
            }
            return [true, ''];
        }
    
        function noWeekendsOrHolidays(date) {
            var noWeekend = $.datepicker.noWeekends(date);
            if (noWeekend[0]) {
                return nationalDays(date);
            } else {
                return noWeekend;
            }
        }
    
    jQuery(document).bind('gform_post_render', function(){
    if (jQuery(".datepicker").length > 0){
        // destroy default Gravity Form datepicker
        jQuery(".datepicker").datepicker('destroy');
        // create new custom datepicker
        jQuery(".datepicker").datepicker({
            // Here I customize language of week days and months labels
    	dayNames: ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"],
            dayNamesMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"],
            monthNames: ["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"],
    		dateFormat: "dd-mm-yy",
    		defaultDate: '+1d',
    		minDate: '+1d',
    		gotoCurrent: true,
    		prevText: '',
    		showOn: 'both',
    		buttonImage: 'http://www.teloaggiusto.io/wp-content/themes/teloaggiustoio/images/calendar_icon.png',
    		buttonImageOnly: true,
    		beforeShowDay: noWeekendsOrHolidays
    
    	});
    }
    });
    Posted 7 years ago on Friday March 29, 2013 | Permalink
  2. bluantinoo
    Member

    Update: I think that the problem is on date format definition, and that the error shows up everytime I choose a day after the 12th day of the month, just because it missplace the day for the month.

    even if I define a customdateFormat as "dd-mm-yy" the validation error keeps saying in error that the format is wrong and I should use "mm-dd-yyyy"!

    I tried to change the dateFormat to in other ways (ex. dd/mm/yy), the field content is correctly printed as I tell in dateFormat option, but the validation field does not change the error and keeps saying that I shoudl use "mm-dd-yyyy" format

    do I need to customize even field validation fuction in some way?

    ----------------------

    UPDATE 2: I confirm that the problem is about dateFormat definition.
    I've just commented the line where I define the dateformat, and everything is working... but why?

    I really need o switch month and day place in dateFormat for localization purpose, any suggestions?

    Posted 7 years ago on Friday March 29, 2013 | Permalink
  3. Handling via priority support.

    Posted 7 years ago on Friday March 29, 2013 | Permalink

This topic has been resolved and has been closed to new replies.