Skip to content

Commit

Permalink
Create gw-use-html5-datepicker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
claygriffiths authored Mar 30, 2022
1 parent 849b916 commit f08ccad
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions experimental/gw-use-html5-datepicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Gravity Wiz // Gravity Forms // Use HTML5 Datepicker
*
* Some users, especially on mobile, may prefer their browser's native datepicker. This snippet will
* convert date fields to use the native datepicker if the visitor is on a mobile device. Optionally, you can
* have the date fields converted for all users (including desktop).
*
* Instructions:
* 1. Install our free Custom JavaScript for Gravity Forms plugin.
* Download the plugin here: https://gravitywiz.com/gravity-forms-custom-javascript/
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
*/

var onlyConvertOnMobile = true; // Change to false if you wish for all devices to use HTML5 datepicker

var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);

if ( isMobile || onlyConvertOnMobile === false ) {
jQuery.fn.datepicker = function() {};

jQuery( '#gform_fields_GFFORMID .ginput_container_date input' )
.attr( 'type', 'date' );
}

0 comments on commit f08ccad

Please sign in to comment.