@@ -49,7 +49,8 @@ public function init() {
4949 return ;
5050 }
5151
52- if ( $ this ->_args ['source_field_id ' ] ) {
52+ // Always load the script if a modifier is provided, even if no source_field_id is set
53+ if ( $ this ->_args ['modifier ' ] || $ this ->_args ['source_field_id ' ] ) {
5354 add_filter ( 'gform_pre_render ' , array ( $ this , 'load_form_script ' ) );
5455 add_filter ( 'gform_register_init_scripts ' , array ( $ this , 'add_init_script ' ) );
5556 add_filter ( 'gform_enqueue_scripts ' , array ( $ this , 'enqueue_form_scripts ' ) );
@@ -300,20 +301,21 @@ public static function output_script() {
300301
301302 self.init = function() {
302303
303- self.$sourceInputs = GWDates.getFieldInputs ( self.sourceFieldId, self.formId );
304-
305- self.$sourceInputs.change( function() {
306- self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
307- } );
304+ if ( self.sourceFieldId ) {
305+ self.$sourceInputs = GWDates.getFieldInputs( self.sourceFieldId, self.formId );
306+ self.$sourceInputs.change( function() {
307+ self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
308+ } );
308309
309- // Listen for GPPA's new `gppa_updated_batch_fields`
310- $( document ).on( 'gppa_updated_batch_fields', function ( e, formId, updatedFieldIDs ) {
311- for ( var i = 0, max = updatedFieldIDs.length; i < max; i ++ ) {
312- if ( self.sourceFieldId === parseInt( updatedFieldIDs[i] ) ) {
313- self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
310+ // Listen for GPPA's new `gppa_updated_batch_fields`
311+ $( document ).on( 'gppa_updated_batch_fields', function ( e, formId, updatedFieldIDs ) {
312+ for ( var i = 0, max = updatedFieldIDs.length; i < max; i ++ ) {
313+ if ( self.sourceFieldId === parseInt( updatedFieldIDs[i] ) ) {
314+ self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
315+ }
314316 }
315- }
316- } );
317+ } );
318+ }
317319
318320 if( typeof self.modifier == 'object' ) {
319321 self.$modifierInputs = self.getInputs( self.modifier.inputId );
@@ -334,7 +336,7 @@ public static function output_script() {
334336
335337 self.populateDate = function( sourceFieldId, targetFieldId, modifier, format ) {
336338
337- var timestamp = GWDates.getFieldTimestamp( sourceFieldId, self.formId, undefined, self.utcOffset );
339+ var timestamp = sourceFieldId ? GWDates.getFieldTimestamp( sourceFieldId, self.formId, undefined, self.utcOffset ) : new Date().getTime( );
338340 if( timestamp === 0 ) {
339341 return;
340342 }
0 commit comments