4
4
*
5
5
* Provides the ability to populate a Date field with a modified date based on the current date or a user-submitted date.
6
6
*
7
- * @version 2.8
7
+ * @version 2.9
8
8
* @author David Smith <[email protected] >
9
9
* @license GPL-2.0+
10
10
* @link http://gravitywiz.com/populate-dates-gravity-form-fields/
@@ -289,6 +289,17 @@ public static function output_script() {
289
289
290
290
( function( $ ) {
291
291
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
+
292
303
window.GWPopulateDate = function( args ) {
293
304
294
305
var self = this;
@@ -308,6 +319,19 @@ public static function output_script() {
308
319
self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
309
320
} );
310
321
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
+
311
335
// Listen for GPPA's new `gppa_updated_batch_fields`
312
336
$( document ).on( 'gppa_updated_batch_fields', function ( e, formId, updatedFieldIDs ) {
313
337
for ( var i = 0, max = updatedFieldIDs.length; i < max; i ++ ) {
0 commit comments