Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions gravity-forms/gw-populate-date.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function init() {
return;
}

if ( $this->_args['source_field_id'] ) {
// Always load the script if a modifier is provided, even if no source_field_id is set
if ( $this->_args['modifier'] || $this->_args['source_field_id'] ) {
add_filter( 'gform_pre_render', array( $this, 'load_form_script' ) );
add_filter( 'gform_register_init_scripts', array( $this, 'add_init_script' ) );
add_filter( 'gform_enqueue_scripts', array( $this, 'enqueue_form_scripts' ) );
Expand Down Expand Up @@ -300,20 +301,21 @@ public static function output_script() {

self.init = function() {

self.$sourceInputs = GWDates.getFieldInputs( self.sourceFieldId, self.formId );

self.$sourceInputs.change( function() {
self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
} );
if( self.sourceFieldId ) {
self.$sourceInputs = GWDates.getFieldInputs( self.sourceFieldId, self.formId );
self.$sourceInputs.change( 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 ++ ) {
if ( self.sourceFieldId === parseInt( updatedFieldIDs[i] ) ) {
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 ++ ) {
if ( self.sourceFieldId === parseInt( updatedFieldIDs[i] ) ) {
self.populateDate( self.sourceFieldId, self.targetFieldId, self.getModifier(), self.format );
}
}
}
} );
} );
}

if( typeof self.modifier == 'object' ) {
self.$modifierInputs = self.getInputs( self.modifier.inputId );
Expand All @@ -334,7 +336,7 @@ public static function output_script() {

self.populateDate = function( sourceFieldId, targetFieldId, modifier, format ) {

var timestamp = GWDates.getFieldTimestamp( sourceFieldId, self.formId, undefined, self.utcOffset );
var timestamp = sourceFieldId ? GWDates.getFieldTimestamp( sourceFieldId, self.formId, undefined, self.utcOffset ) : new Date().getTime();
if( timestamp === 0 ) {
return;
}
Expand Down
Loading