From f08ccad35817e81300fd80914c054a7f5939f3eb Mon Sep 17 00:00:00 2001 From: Clay Griffiths Date: Wed, 30 Mar 2022 18:54:56 -0500 Subject: [PATCH] Create gw-use-html5-datepicker.js --- experimental/gw-use-html5-datepicker.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 experimental/gw-use-html5-datepicker.js diff --git a/experimental/gw-use-html5-datepicker.js b/experimental/gw-use-html5-datepicker.js new file mode 100644 index 000000000..433c29139 --- /dev/null +++ b/experimental/gw-use-html5-datepicker.js @@ -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' ); +}