diff --git a/gravity-forms/gw-populate-date.php b/gravity-forms/gw-populate-date.php index 862585a74..a014d3494 100644 --- a/gravity-forms/gw-populate-date.php +++ b/gravity-forms/gw-populate-date.php @@ -4,7 +4,7 @@ * * 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.9 * @author David Smith * @license GPL-2.0+ * @link http://gravitywiz.com/populate-dates-gravity-form-fields/ @@ -288,6 +288,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; @@ -307,6 +318,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 ++ ) {