Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sakibstime/beb08987d958f0ffc806bcac6810c5bd to your computer and use it in GitHub Desktop.
Save sakibstime/beb08987d958f0ffc806bcac6810c5bd to your computer and use it in GitHub Desktop.
Jetformbuilder, JavaScript Snippet to Disable Past Dates for Jetformbuilder
Jetformbuilder, Datefield, Disable Past Dates.
Dont forget to add your field name ( YOUR FIELD NAME ), change it to your field name.
_____________________________________________________________________
// JavaScript Snippet to Disable Past Dates for Jetformbuilder
jQuery(document).ready(function($) {
// Function to disable past dates
function disablePastDates() {
// Selector for the date field (name and class)
var dateFieldSelector = 'input[name="YOUR FIELD NAME"].jet-form-builder__field.date-field';
// Initialize or update the date field
$(dateFieldSelector).attr('min', function() {
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
// Format today's date as YYYY-MM-DD
return yyyy + '-' + mm + '-' + dd;
});
}
// Run the function to disable past dates
disablePastDates();
// Optional: Re-run the function if the form is dynamically updated or on field focus
$(document).on('focus', 'input[name="YOUR FIELD NAME"].jet-form-builder__field.date-field', function() {
disablePastDates();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment