May 09, 2018
It’s unfortunate that the Time Field in Gravity Forms does not have more custom options available.
Contrarily, the Date Field, allows for a calendar icon, and drop downs, but the Time Field doesn’t have a default placeholder option to populate the current time, or an alternate view to allow for drop downs showing 12 or 24 hour time.
So I had to turn to jQuery…
24-Hour Format:
var dt = new Date(); jQuery("#input_4_66_1").val(dt.getHours()); // input ID of Hours field jQuery("#input_4_66_2").val(dt.getMinutes()); // inputer ID of Minutes field
12-Hour Format:
var time = new Date(); hours = time.getHours() % 12 || 12; minutes = time.toLocaleString('en-US', { minute:'numeric', hour12: true });
Sourced here.
Is this added to the theme’s function.php?
Hello, thanks for reaching out.
This is for your theme’s .js file. Target the ID of the field from your Gravity Form.