Forked from Qubadi/gist:1a5ec426653964ba4e36b7ee212c8606
Created
February 24, 2024 17:39
-
-
Save sakibstime/beb08987d958f0ffc806bcac6810c5bd to your computer and use it in GitHub Desktop.
Jetformbuilder, JavaScript Snippet to Disable Past Dates for Jetformbuilder
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
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