Skip to content

Commit 6bb18b9

Browse files
committed
gw-time-sensitive-choices.php: Added support for inline datepickers.
1 parent 81c10b3 commit 6bb18b9

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

gravity-forms/gw-time-sensitive-choices.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function output_script() {
7171

7272
var self = this;
7373

74+
self.intialized = false;
75+
7476
for( var prop in args ) {
7577
if( args.hasOwnProperty( prop ) ) {
7678
self[ prop ] = args[ prop ];
@@ -85,10 +87,12 @@ public function output_script() {
8587
self.bindEvents();
8688
setTimeout( function() {
8789
self.initializeChoices();
90+
self.initialized = true;
8891
} );
8992
} else {
9093
self.bindEvents();
9194
self.initializeChoices();
95+
self.initialized = true;
9296
}
9397

9498
};
@@ -111,7 +115,16 @@ public function output_script() {
111115

112116
if ( self.$date.length ) {
113117
self.$date.on( 'change', function() {
114-
self.evaluateChoices();
118+
/**
119+
* Inline datepickers trigger an early change event when they set the default date. This
120+
* triggers EvaluateChoices to run prematurely, disabling choices based on the selected
121+
* date. This leads InitializeChoices to assume these disabled choices were set on page
122+
* load and marks them as permanently disabled. To prevent this, InitializeChoices must
123+
* always run before EvaluateChoices.
124+
*/
125+
if ( self.initialized ) {
126+
self.evaluateChoices();
127+
}
115128
} );
116129
}
117130

@@ -124,7 +137,7 @@ public function output_script() {
124137
var currentTime = self.getCurrentServerTime();
125138

126139
if ( self.dateFieldId ) {
127-
var selectedDate = self.$date.datepicker( 'getDate' );
140+
var selectedDate = self.getSelectedDate();
128141
if ( selectedDate !== null ) {
129142
var currentDate = self.getCurrentServerTime();
130143
currentDate.setHours(0, 0, 0, 0);
@@ -211,7 +224,11 @@ public function output_script() {
211224
}
212225

213226
self.getSelectedDate = function() {
214-
return self.$date.datepicker( 'getDate' );
227+
let $datepicker = self.$date;
228+
if ( $datepicker.hasClass( 'has-inline-datepicker' ) ) {
229+
$datepicker = $( '#datepicker_{0}_{1}'.gformFormat( self.formId, self.dateFieldId ) );
230+
}
231+
return $datepicker.datepicker( 'getDate' );
215232
}
216233

217234
/**

0 commit comments

Comments
 (0)