Skip to content

Commit b54aa15

Browse files
authored
gw-populate-date.php: Added support for dynamic populated modifier values trigerring Populate Date updates.
1 parent e579ea3 commit b54aa15

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

gravity-forms/gw-populate-date.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Provides the ability to populate a Date field with a modified date based on the current date or a user-submitted date.
66
*
7-
* @version 2.8
7+
* @version 2.9
88
* @author David Smith <[email protected]>
99
* @license GPL-2.0+
1010
* @link http://gravitywiz.com/populate-dates-gravity-form-fields/
@@ -289,6 +289,17 @@ public static function output_script() {
289289

290290
( function( $ ) {
291291

292+
if ( ! String.prototype.format ) {
293+
String.prototype.format = function() {
294+
var args = arguments;
295+
return this.replace( /{(\d+)}/g, function( match, number ) {
296+
return typeof args[ number ] !== 'undefined'
297+
? args[ number ]
298+
: match;
299+
});
300+
};
301+
}
302+
292303
window.GWPopulateDate = function( args ) {
293304

294305
var self = this;
@@ -308,6 +319,19 @@ public static function output_script() {
308319
self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
309320
} );
310321

322+
// Listen for any dynamic content loaded on modifier field (if existing) to refresh values on Target.
323+
if ( self.modifier && self instanceof GWPopulateDate ) {
324+
var modifier = self.modifier.inputId;
325+
326+
if ( modifier ) {
327+
var modifierParent = '#field_' + self.formId + '_' + modifier;
328+
var modifierTarget = '#input_' + self.formId + '_' + modifier;
329+
$( modifierParent ).on( 'change', modifierTarget, function() {
330+
self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
331+
} );
332+
}
333+
}
334+
311335
// Listen for GPPA's new `gppa_updated_batch_fields`
312336
$( document ).on( 'gppa_updated_batch_fields', function ( e, formId, updatedFieldIDs ) {
313337
for ( var i = 0, max = updatedFieldIDs.length; i < max; i ++ ) {

0 commit comments

Comments
 (0)