Skip to content

Commit 2cd72c4

Browse files
committed
gw-populate-date.php: Added support for dynamic populated modifier values trigerring Populate Date updates.
1 parent 62668ca commit 2cd72c4

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/
@@ -288,6 +288,17 @@ public static function output_script() {
288288

289289
( function( $ ) {
290290

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

293304
var self = this;
@@ -307,6 +318,19 @@ public static function output_script() {
307318
self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
308319
} );
309320

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

0 commit comments

Comments
 (0)