Advertisement
Guest User

jQuery UI Custom Datepicker for Gravity Forms

a guest
Feb 20th, 2013
361
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date Format
  2. var initDatePicker = function () {
  3.     $( "#input_2_5" ).datepicker({
  4.         minDate:    1,
  5.         maxDate:    "+1m",
  6.         dateFormat: "DD, d MM, yy"
  7.     });
  8.    
  9.     $("#input_2_5").keypress(function (e) {
  10.         // PreventDefault workaround for older browsers
  11.         if (!e.preventDefault) {
  12.             e.returnValue = false;
  13.         } else {
  14.             e.preventDefault();
  15.         }
  16.     });
  17.    
  18.     $("#input_2_5").keydown(function(e){
  19.         //If delete or backspace pressed
  20.         if (e.keyCode == 46 || e.keyCode == 8) {
  21.             $(this).val(''); // Clear text
  22.             $(this).datepicker("hide"); // Hide the datepicker calendar (if displayed)
  23.             $(this).blur(); // Unfocus from the field
  24.         }
  25.  
  26.         //Prevent user from manually entering date (have to use the datepicker box)
  27.         // PreventDefault workaround for older browsers
  28.         if (!e.preventDefault) {
  29.             e.returnValue = false;
  30.         } else {
  31.             e.preventDefault();
  32.         }
  33.     });
  34. };
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement