From 4a5f1c820c1f74c4e3763b89e7b5dffa6f3309dd Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Mon, 21 Nov 2022 23:32:07 +0530 Subject: [PATCH 1/3] `gw-populate-date.php`: Updated snippet to tap dynamic content loaded by field value modifier. `gw-populate-date.php`: Updated snippet to tap dynamic content loaded by field value modifier. `gw-populate-date.php`: Updated snippet to tap dynamic content loaded by field value modifier. `gw-populate-date.php`: Updated snippet to tap dynamic content loaded by field value modifier. --- gravity-forms/gw-populate-date.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gravity-forms/gw-populate-date.php b/gravity-forms/gw-populate-date.php index c9cb74f43..041904d7b 100644 --- a/gravity-forms/gw-populate-date.php +++ b/gravity-forms/gw-populate-date.php @@ -300,6 +300,19 @@ public static function output_script() { self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format ); } ); + // Listen for any dynamic content loaded on modifier field (if existing) to refresh values on Target. + if ( self.modifier && self instanceof GWPopulateDate ) { + var modifier = self.modifier.inputId; + + if ( modifier ) { + var modifierParent = '#field_' + self.formId + '_' + modifier; + var modifierTarget = '#input_' + self.formId + '_' + modifier; + $( modifierParent ).on( 'change', modifierTarget, function() { + self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format ); + } ); + } + } + // Listen for GPPA's new `gppa_updated_batch_fields` $( document ).on( 'gppa_updated_batch_fields', function ( e, formId, updatedFieldIDs ) { for ( var i = 0, max = updatedFieldIDs.length; i < max; i ++ ) { From e1122d668cdfe703438e725517d31dd435c50e45 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Wed, 19 Mar 2025 12:12:14 +0530 Subject: [PATCH 2/3] `gw-populate-date.php`: Fixed an issue where dynamic population did not trigger date population. --- gravity-forms/gw-populate-date.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gravity-forms/gw-populate-date.php b/gravity-forms/gw-populate-date.php index 041904d7b..416b151a2 100644 --- a/gravity-forms/gw-populate-date.php +++ b/gravity-forms/gw-populate-date.php @@ -281,6 +281,17 @@ public static function output_script() { ( function( $ ) { + if ( ! String.prototype.format ) { + String.prototype.format = function() { + var args = arguments; + return this.replace(/{(\d+)}/g, function( match, number ) { + return typeof args[number] !== 'undefined' + ? args[number] + : match; + }); + }; + } + window.GWPopulateDate = function( args ) { var self = this; From a6b97e032254112116defb1d6189d1eed07cf330 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Wed, 19 Mar 2025 12:17:18 +0530 Subject: [PATCH 3/3] `gw-populate-date.php`: Fixed an issue where dynamic population did not trigger date population. --- gravity-forms/gw-populate-date.php | 85 ++++++++---------------------- 1 file changed, 23 insertions(+), 62 deletions(-) diff --git a/gravity-forms/gw-populate-date.php b/gravity-forms/gw-populate-date.php index dc1ab7ff9..066beaf6b 100644 --- a/gravity-forms/gw-populate-date.php +++ b/gravity-forms/gw-populate-date.php @@ -4,17 +4,16 @@ * * Provides the ability to populate a Date field with a modified date based on the current date or a user-submitted date. * - * @version 2.8 + * @version 2.6 * @author David Smith * @license GPL-2.0+ * @link http://gravitywiz.com/populate-dates-gravity-form-fields/ */ class GW_Populate_Date { - protected static $is_script_output = false; + protected $_args; - private $_args = array(); - private $_field_values = array(); + protected static $is_script_output = false; public function __construct( $args = array() ) { @@ -28,7 +27,6 @@ public function __construct( $args = array() ) { 'min_date' => false, 'enable_i18n' => false, 'override_on_submission' => false, - 'utc_offset' => get_option( 'gmt_offset' ), // Used only for time calculations on the current date. ) ); $this->_field_values = array(); @@ -49,8 +47,7 @@ public function init() { return; } - // Always load the script if a modifier is provided, even if no source_field_id is set - if ( $this->_args['modifier'] || $this->_args['source_field_id'] ) { + if ( $this->_args['source_field_id'] ) { add_filter( 'gform_pre_render', array( $this, 'load_form_script' ) ); add_filter( 'gform_register_init_scripts', array( $this, 'add_init_script' ) ); add_filter( 'gform_enqueue_scripts', array( $this, 'enqueue_form_scripts' ) ); @@ -245,9 +242,7 @@ public function get_modified_date( $field, $timestamp = false ) { $hour = 12; } } - // Ensure the time value is retained as a String. - // If saved in array format, it will not reload the value after conditional viewing/hiding. - $date = "{$hour}:{$minute} {$ampm}"; + $date = array( $hour, $minute, $ampm ); } elseif ( $this->_args['enable_i18n'] ) { $date = strftime( $format, $timestamp ); } else { @@ -287,11 +282,10 @@ public static function output_script() {