Created
December 18, 2019 16:58
-
-
Save mingodev/63a644199e77e3283c470a27cd5cf748 to your computer and use it in GitHub Desktop.
Add start date to end date minimum in date input (Contact Form 7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var medieval = medieval || {}; | |
var start; var end; | |
medieval.calendarFix = function ($) { | |
"use strict"; | |
let initialize = function () { | |
start = jQuery('input.date-start').first(); | |
end = jQuery('input.date-end').first(); | |
start.on('change', function() { | |
let startDate = new Date($(this).val()); | |
startDate.setDate(startDate.getDate() + 3); | |
let formattedStartDate = formatDate(startDate); | |
end.attr('min', formattedStartDate); | |
}); | |
}; | |
let formatDate = function (dateToFormat) { | |
let year = dateToFormat.getFullYear(); | |
let month = dateToFormat.getMonth() + 1; | |
if (month < 10) month = '0' + month; | |
let day = dateToFormat.getDate(); | |
if (day < 10) day = '0' + day; | |
return year + '-' + month + '-' + day; | |
}; | |
return { | |
init: function () { | |
initialize(); | |
} | |
}; | |
}(jQuery); | |
jQuery(document).ready(function () { | |
medieval.calendarFix.init(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fix Calendar | |
add_action('wp_enqueue_scripts', function () { | |
if (!is_front_page()) return; | |
wp_enqueue_script('calendar-fix-js', get_stylesheet_directory_uri() . '/assets/js/calendar-fix.js', ['jquery'], null, true); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment