Created
July 25, 2012 05:09
-
-
Save elijahmanor/3174513 to your computer and use it in GitHub Desktop.
Just In Time Initialization of jQuery UI Date Picker On Focus
This file contains 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
$( document ).ready( function() { | |
$( "input.date" ).datepicker({ | |
minDate: moment().subtract( "months", 1 ).toDate(), | |
maxDate: moment().add( "months", 1 ).toDate(), | |
dateFormat: "d M, y", | |
constrainInput: true, | |
beforeShowDay: $.datepicker.noWeekends | |
}); | |
}); |
This file contains 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
<form class="form-horizontal well"> | |
<fieldset> | |
<div class="control-group"> | |
<label class="control-label" for="firstName">First Name</label> | |
<div class="controls"> | |
<input id="firstName" type="text" class="input-xlarge"> | |
</div> | |
</div> | |
<!-- More HTML... --> | |
<div class="control-group"> | |
<label class="control-label" for="birthday">Birthday</label> | |
<div class="controls"> | |
<input id="birthday" type="text" class="date input-xlarge"> | |
</div> | |
</div> | |
<div class="form-actions"> | |
<button type="submit" class="btn btn-primary">Save changes</button> | |
<button class="btn">Cancel</button> | |
</div> | |
</fieldset> | |
</form> |
This file contains 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
$( document ).on( "focus", "input.date:not(.hasDatepicker)", function() { | |
toastr.info( "Initializing " + this.id ); | |
$( this ).datepicker({ | |
minDate: moment().subtract( "months", 1 ).toDate(), | |
maxDate: moment().add( "months", 1 ).toDate(), | |
dateFormat: "d M, y", | |
constrainInput: true, | |
beforeShowDay: $.datepicker.noWeekends | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment