@@ -125,6 +125,11 @@ export interface DatepickerOptions extends BaseOptions {
125
125
* @default false
126
126
*/
127
127
showClearBtn : boolean ;
128
+ /**
129
+ * Autosubmit calendar day select to input field
130
+ * @default false
131
+ */
132
+ autoSubmit : true ;
128
133
/**
129
134
* Internationalization options.
130
135
*/
@@ -156,6 +161,17 @@ export interface DatepickerOptions extends BaseOptions {
156
161
* @default null
157
162
*/
158
163
onInputInteraction : ( ( ) => void ) | null ;
164
+ /**
165
+ * Callback function for interaction with confirm button.
166
+ * @default null
167
+ */
168
+ onConfirm : ( ( ) => void ) | null ;
169
+ /**
170
+ * Callback function for interaction with close button.
171
+ * @default null
172
+ */
173
+ onCancel : ( ( ) => void ) | null ;
174
+
159
175
/** Field used for internal calculations DO NOT CHANGE IT */
160
176
minYear ?: number ;
161
177
/** Field used for internal calculations DO NOT CHANGE IT */
@@ -218,6 +234,8 @@ const _defaults: DatepickerOptions = {
218
234
container : null ,
219
235
// Show clear button
220
236
showClearBtn : false ,
237
+ // Autosubmit
238
+ autoSubmit : true ,
221
239
// internationalization
222
240
i18n : {
223
241
cancel : 'Cancel' ,
@@ -263,6 +281,8 @@ const _defaults: DatepickerOptions = {
263
281
onSelect : null ,
264
282
onDraw : null ,
265
283
onInputInteraction : null ,
284
+ onConfirm : null ,
285
+ onCancel : null ,
266
286
} ;
267
287
268
288
export class Datepicker extends Component < DatepickerOptions > {
@@ -272,10 +292,10 @@ export class Datepicker extends Component<DatepickerOptions> {
272
292
calendarEl : HTMLElement ;
273
293
274
294
/** CLEAR button instance. */
275
- clearBtn : HTMLElement ;
295
+ // clearBtn: HTMLElement;
276
296
/** DONE button instance */
277
- doneBtn : HTMLElement ;
278
- cancelBtn : HTMLElement ;
297
+ /* doneBtn: HTMLElement;
298
+ cancelBtn: HTMLElement;*/
279
299
280
300
containerEl : HTMLElement ;
281
301
yearTextEl : HTMLElement ;
@@ -290,6 +310,7 @@ export class Datepicker extends Component<DatepickerOptions> {
290
310
calendars : [ { month : number ; year : number } ] ;
291
311
private _y : number ;
292
312
private _m : number ;
313
+ private footer : HTMLElement ;
293
314
static _template : string ;
294
315
295
316
constructor ( el : HTMLInputElement , options : Partial < DatepickerOptions > ) {
@@ -467,12 +488,17 @@ export class Datepicker extends Component<DatepickerOptions> {
467
488
}
468
489
}
469
490
470
- if ( this . options . showClearBtn ) {
491
+ /* if (this.options.showClearBtn) {
471
492
this.clearBtn.style.visibility = '';
472
493
this.clearBtn.innerText = this.options.i18n.clear;
473
494
}
474
495
this.doneBtn.innerText = this.options.i18n.done;
475
- this . cancelBtn . innerText = this . options . i18n . cancel ;
496
+ this.cancelBtn.innerText = this.options.i18n.cancel;*/
497
+ Utils . createButton ( this . footer , this . options . i18n . clear , [ 'datepicker-clear' ] , this . options . showClearBtn , this . _handleClearClick ) ;
498
+
499
+ if ( ! this . options . autoSubmit ) {
500
+ Utils . createConfirmationContainer ( this . footer , this . options . i18n . done , this . options . i18n . cancel , this . _confirm , this . _cancel ) ;
501
+ }
476
502
477
503
if ( this . options . container ) {
478
504
const optEl = this . options . container ;
@@ -1085,12 +1111,12 @@ export class Datepicker extends Component<DatepickerOptions> {
1085
1111
this . el . addEventListener ( 'keydown' , this . _handleInputKeydown ) ;
1086
1112
this . el . addEventListener ( 'change' , this . _handleInputChange ) ;
1087
1113
this . calendarEl . addEventListener ( 'click' , this . _handleCalendarClick ) ;
1088
- this . doneBtn . addEventListener ( 'click' , ( ) => this . setInputValues ( ) ) ;
1089
- this . cancelBtn . addEventListener ( 'click' , this . close ) ;
1114
+ /* this.doneBtn.addEventListener('click', this._confirm );
1115
+ this.cancelBtn.addEventListener('click', this._cancel );
1090
1116
1091
1117
if (this.options.showClearBtn) {
1092
1118
this.clearBtn.addEventListener('click', this._handleClearClick);
1093
- }
1119
+ }*/
1094
1120
}
1095
1121
1096
1122
_setupVariables ( ) {
@@ -1102,12 +1128,12 @@ export class Datepicker extends Component<DatepickerOptions> {
1102
1128
this . calendarEl = this . containerEl . querySelector ( '.datepicker-calendar' ) ;
1103
1129
this . yearTextEl = this . containerEl . querySelector ( '.year-text' ) ;
1104
1130
this . dateTextEl = this . containerEl . querySelector ( '.date-text' ) ;
1105
- if ( this . options . showClearBtn ) {
1131
+ /* if (this.options.showClearBtn) {
1106
1132
this.clearBtn = this.containerEl.querySelector('.datepicker-clear');
1107
1133
}
1108
- // TODO: This should not be part of the datepicker
1109
1134
this.doneBtn = this.containerEl.querySelector('.datepicker-done');
1110
- this . cancelBtn = this . containerEl . querySelector ( '.datepicker-cancel' ) ;
1135
+ this.cancelBtn = this.containerEl.querySelector('.datepicker-cancel');*/
1136
+ this . footer = this . containerEl . querySelector ( '.datepicker-footer' ) ;
1111
1137
1112
1138
this . formats = {
1113
1139
d : ( date : Date ) => {
@@ -1199,7 +1225,7 @@ export class Datepicker extends Component<DatepickerOptions> {
1199
1225
this . _handleDateRangeCalendarClick ( selectedDate ) ;
1200
1226
}
1201
1227
1202
- this . _finishSelection ( ) ;
1228
+ if ( this . options . autoSubmit ) this . _finishSelection ( ) ;
1203
1229
} else if ( target . closest ( '.month-prev' ) ) {
1204
1230
this . prevMonth ( ) ;
1205
1231
} else if ( target . closest ( '.month-next' ) ) {
@@ -1230,6 +1256,7 @@ export class Datepicker extends Component<DatepickerOptions> {
1230
1256
_clearDates = ( ) => {
1231
1257
this . date = null ;
1232
1258
this . endDate = null ;
1259
+ this . draw ( ) ;
1233
1260
} ;
1234
1261
1235
1262
_handleMonthChange = ( e ) => {
@@ -1302,7 +1329,17 @@ export class Datepicker extends Component<DatepickerOptions> {
1302
1329
// Set input value to the selected date and close Datepicker
1303
1330
_finishSelection = ( ) => {
1304
1331
this . setInputValues ( ) ;
1305
- this . close ( ) ;
1332
+ // Commented out because of function deprecations
1333
+ // this.close();
1334
+ } ;
1335
+
1336
+ _confirm = ( ) => {
1337
+ this . _finishSelection ( ) ;
1338
+ if ( typeof this . options . onConfirm === 'function' ) this . options . onConfirm . call ( this ) ;
1339
+ }
1340
+
1341
+ _cancel = ( ) => {
1342
+ if ( typeof this . options . onCancel === 'function' ) this . options . onCancel . call ( this ) ;
1306
1343
} ;
1307
1344
1308
1345
// deprecated
@@ -1327,11 +1364,11 @@ export class Datepicker extends Component<DatepickerOptions> {
1327
1364
<div class="datepicker-calendar-container">
1328
1365
<div class="datepicker-calendar"></div>
1329
1366
<div class="datepicker-footer">
1330
- <button class="btn-flat datepicker-clear waves-effect" style="visibility: hidden;" type="button"></button>
1367
+ <!--< button class="btn-flat datepicker-clear waves-effect" style="visibility: hidden;" type="button"></button>
1331
1368
<div class="confirmation-btns">
1332
1369
<button class="btn-flat datepicker-cancel waves-effect" type="button"></button>
1333
1370
<button class="btn-flat datepicker-done waves-effect" type="button"></button>
1334
- </div>
1371
+ </div>-->
1335
1372
</div>
1336
1373
</div>
1337
1374
</div>` ;
0 commit comments