-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathdaterangepicker.ts
4714 lines (4651 loc) · 214 KB
/
daterangepicker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path='../calendar/calendar-model.d.ts'/>
import { Property, EventHandler, Internationalization, NotifyPropertyChanges, detach, getUniqueID } from '@syncfusion/ej2-base';
import { KeyboardEvents, BaseEventArgs, KeyboardEventArgs, Event, EmitType, Browser, L10n, ChildProperty } from '@syncfusion/ej2-base';
import { addClass, createElement, remove, closest, select, prepend, removeClass, attributes, Collection } from '@syncfusion/ej2-base';
import { isNullOrUndefined, isUndefined, formatUnit, setValue, rippleEffect, merge, extend, isBlazor } from '@syncfusion/ej2-base';
import { CalendarView, CalendarBase, NavigatedEventArgs, RenderDayCellEventArgs, CalendarType } from '../calendar/calendar';
import { Popup } from '@syncfusion/ej2-popups';
import { Button } from '@syncfusion/ej2-buttons';
import { BlurEventArgs, FocusEventArgs, ClearedEventArgs } from '../calendar/calendar';
import { Input, InputObject, FloatLabelType } from '@syncfusion/ej2-inputs';
import { ListBase} from '@syncfusion/ej2-lists';
import { PresetsModel, DateRangePickerModel } from './daterangepicker-model';
const DATERANGEWRAPPER: string = 'e-date-range-wrapper';
const INPUTCONTAINER: string = 'e-input-group';
const DATERANGEICON: string = 'e-input-group-icon e-range-icon e-icons';
const POPUP: string = 'e-popup';
const LEFTCALENDER: string = 'e-left-calendar';
const RIGHTCALENDER: string = 'e-right-calendar';
const LEFTCONTAINER: string = 'e-left-container';
const RIGHTCONTAINER: string = 'e-right-container';
const ROOT: string = 'e-daterangepicker';
const LIBRARY: string = 'e-lib';
const CONTROL: string = 'e-control';
const ERROR: string = 'e-error';
const ACTIVE: string = 'e-active';
const STARTENDCONTAINER: string = 'e-start-end';
const STARTDATE: string = 'e-start-date';
const ENDDATE: string = 'e-end-date';
const STARTBUTTON: string = 'e-start-btn';
const INPUTFOCUS: string = 'e-input-focus';
const ENDBUTTON: string = 'e-end-btn';
const RANGEHOVER: string = 'e-range-hover';
const OTHERMONTH: string = 'e-other-month';
const STARTLABEL: string = 'e-start-label';
const ENDLABEL: string = 'e-end-label';
const DISABLED: string = 'e-disabled';
const SELECTED: string = 'e-selected';
const CALENDAR: string = 'e-calendar';
const NEXTICON: string = 'e-next';
const PREVICON: string = 'e-prev';
const HEADER: string = 'e-header';
const TITLE: string = 'e-title';
const ICONCONTAINER: string = 'e-icon-container';
const RANGECONTAINER: string = 'e-date-range-container';
const RANGEHEADER: string = 'e-range-header';
const PRESETS: string = 'e-presets';
const FOOTER: string = 'e-footer';
const RANGEBORDER: string = 'e-range-border';
const TODAY: string = 'e-today';
const FOCUSDATE: string = 'e-focused-date';
const CONTENT: string = 'e-content';
const DAYSPAN: string = 'e-day-span';
const WEEKNUMBER: string = 'e-week-number';
const DATEDISABLED: string = 'e-date-disabled';
const ICONDISABLED: string = 'e-icon-disabled';
const CALENDARCONTAINER: string = 'e-calendar-container';
const SEPARATOR: string = 'e-separator';
const APPLY: string = 'e-apply';
const CANCEL: string = 'e-cancel';
const DEVICE: string = 'e-device';
const OVERLAY: string = 'e-overlay';
const CHANGEICON: string = 'e-change-icon e-icons';
const LISTCLASS: string = 'e-list-item';
const RTL: string = 'e-rtl';
const HOVER: string = 'e-hover';
const OVERFLOW: string = 'e-range-overflow';
const OFFSETVALUE: number = 4;
const PRIMARY: string = 'e-primary';
const FLAT: string = 'e-flat';
const CSS: string = 'e-css';
const ZOOMIN: string = 'e-zoomin';
const NONEDITABLE: string = 'e-non-edit';
const DAYHEADERLONG: string = 'e-daterange-day-header-lg';
const HIDDENELEMENT: string = 'e-daterange-hidden';
const wrapperAttr: string[] = ['title', 'class', 'style'];
export class Presets extends ChildProperty<Presets> {
/**
* Defines the label string of the preset range.
*/
@Property()
public label: string;
/**
* Defines the start date of the preset range.
*/
@Property()
public start: Date;
/**
* Defines the end date of the preset range
*/
@Property()
public end: Date;
}
export interface DateRange {
/** Defines the start date */
start?: Date
/** Defines the end date */
end?: Date
}
export interface RangeEventArgs extends BaseEventArgs {
/**
* Defines the value
*/
value?: Date[] | DateRange
/** Defines the value string in the input element */
text?: string
/** Defines the start date */
startDate?: Date
/** Defines the end date */
endDate?: Date
/** Defines the day span between the range */
daySpan?: number
/** Specifies the element. */
element?: HTMLElement | HTMLInputElement
/**
* Specifies the original event arguments.
*/
event?: MouseEvent | KeyboardEvent | TouchEvent | Event
/**
* If the event is triggered by interaction, it returns true. Otherwise, it returns false.
*/
isInteracted?: boolean
}
export interface RangePopupEventArgs {
/** Defines the range string in the input element */
date: string
/** Defines the DateRangePicker model */
model: DateRangePickerModel
/**
* Illustrates whether the current action needs to be prevented or not.
*/
cancel?: boolean
/**
* Defines the DateRangePicker popup object.
*
* @deprecated
*/
popup?: Popup
/**
* Specifies the original event arguments.
*/
event?: MouseEvent | KeyboardEvent | Event
/**
* Specifies the node to which the popup element to be appended.
*/
appendTo?: HTMLElement
}
export interface RangeFormatObject {
/**
* Specifies the format in which the date format will process
*/
skeleton?: string
}
/**
* Represents the DateRangePicker component that allows user to select the date range from the calendar
* or entering the range through the input element.
* ```html
* <input id="daterangepicker"/>
* ```
* ```typescript
* <script>
* var dateRangePickerObj = new DateRangePicker({ startDate: new Date("05/07/2017"), endDate: new Date("10/07/2017") });
* dateRangePickerObj.appendTo("#daterangepicker");
* </script>
* ```
*/
@NotifyPropertyChanges
export class DateRangePicker extends CalendarBase {
private popupObj: Popup;
private inputWrapper: InputObject;
private popupWrapper: HTMLElement;
private rightCalendar: HTMLElement;
private leftCalendar: HTMLElement;
private deviceCalendar: HTMLElement;
private leftCalCurrentDate: Date;
private initStartDate: Date;
private initEndDate: Date;
private startValue: Date;
private endValue: Date;
private modelValue: Date[] | DateRange;
private rightCalCurrentDate: Date;
private leftCalPrevIcon: HTMLElement;
private leftCalNextIcon: HTMLElement;
private leftTitle: HTMLElement;
private rightTitle: HTMLElement;
private rightCalPrevIcon: HTMLElement;
private rightCalNextIcon: HTMLElement;
private inputKeyboardModule: KeyboardEvents;
protected leftKeyboardModule: KeyboardEvents;
protected rightKeyboardModule: KeyboardEvents;
private previousStartValue: Date;
private previousEndValue: Date;
private applyButton: Button;
private cancelButton: Button;
private startButton: Button;
private endButton: Button;
private cloneElement: HTMLElement;
private l10n: L10n;
private isCustomRange: boolean = false;
private isCustomWindow: boolean = false;
private presetsItem: { [key: string]: Object }[] = [];
private liCollections: HTMLElement[] = [];
private activeIndex: number;
private presetElement: HTMLElement;
private previousEleValue: string = '';
private targetElement: HTMLElement;
private disabledDayCnt: number;
private angularTag: string;
private inputElement: HTMLInputElement;
private modal: HTMLElement;
private firstHiddenChild: HTMLInputElement;
private secondHiddenChild: HTMLInputElement;
private isKeyPopup: boolean = false;
private dateDisabled: boolean = false;
private navNextFunction: Function;
private navPrevFunction: Function;
private deviceNavNextFunction: Function;
private deviceNavPrevFunction: Function;
private isRangeIconClicked: boolean = false;
private isMaxDaysClicked: boolean = false;
private popupKeyboardModule: KeyboardEvents;
private presetKeyboardModule: KeyboardEvents;
private btnKeyboardModule: KeyboardEvents;
private virtualRenderCellArgs: RenderDayCellEventArgs;
private disabledDays: Date[] = [];
private isMobile: boolean;
private keyInputConfigs: { [key: string]: string };
private defaultConstant: Object;
private preventBlur: boolean = false;
private preventFocus: boolean = false;
private valueType: Date[] | DateRange;
private closeEventArgs: RangePopupEventArgs;
private openEventArgs: RangePopupEventArgs;
private controlDown: KeyboardEventArgs;
private startCopy: Date;
private endCopy: Date;
private formElement: Element;
private formatString: string;
protected tabIndex: string;
private invalidValueString: string = null;
private dateRangeOptions: DateRangePickerModel;
private mobileRangePopupWrap: HTMLElement;
protected isAngular: boolean = false;
protected preventChange: boolean = false;
/**
* Gets or sets the start and end date of the Calendar.
* {% codeBlock src='daterangepicker/value/index.md' %}{% endcodeBlock %}
*
* @default null
*/
@Property(null)
public value: Date[] | DateRange;
/**
* Enable or disable the persisting component's state between the page reloads. If enabled, following list of states will be persisted.
* 1. startDate
* 2. endDate
* 3. value
*
* @default false
*/
@Property(false)
public enablePersistence: boolean;
/**
* Gets or sets the minimum date that can be selected in the calendar-popup.
*
* @default new Date(1900, 00, 01)
* @blazorDefaultValue new DateTime(1900, 01, 01)
*/
@Property(new Date(1900, 0, 1))
public min: Date;
/**
* Gets or sets the maximum date that can be selected in the calendar-popup.
*
* @default new Date(2099, 11, 31)
* @blazorDefaultValue new DateTime(2099, 12, 31)
*/
@Property(new Date(2099, 11, 31))
public max: Date;
/**
* Overrides the global culture and localization value for this component. Default global culture is 'en-US'.
*
* @default 'en-US'
*/
@Property(null)
public locale: string;
/**
* Gets or sets the Calendar's first day of the week. By default, the first day of the week will be based on the current culture.
* > For more details about firstDayOfWeek refer to
* [`First day of week`](../../daterangepicker/customization#first-day-of-week) documentation.
*
* @default null
*/
@Property(null)
public firstDayOfWeek: number;
/**
* Determines whether the week number of the Calendar is to be displayed or not.
* The week number is displayed in every week row.
* > For more details about weekNumber refer to
* [`Calendar with week number`](../../calendar/how-to/render-the-calendar-with-week-numbers)documentation.
*
* @default false
*/
@Property(false)
public weekNumber: boolean;
/**
* Gets or sets the Calendar's Type like gregorian or islamic.
*
* @default Gregorian
* @private
*/
@Property('Gregorian')
public calendarMode: CalendarType;
/**
* By default, the popup opens while clicking on the daterangepicker icon.
* If you want to open the popup while focusing the daterange input then specify its value as true.
*
* @default false
*/
@Property(false)
public openOnFocus : boolean;
/**
* Triggers when Calendar is created.
*
* @event created
* @blazorProperty 'Created'
*/
@Event()
public created: EmitType<Object>;
/**
* Triggers when Calendar is destroyed.
*
* @event destroyed
* @blazorProperty 'Destroyed'
*/
@Event()
public destroyed: EmitType<Object>;
/**
* Triggers when the Calendar value is changed.
*
* @event change
* @blazorProperty 'ValueChange'
*/
@Event()
public change: EmitType<RangeEventArgs>;
/**
* Triggers when daterangepicker value is cleared using clear button.
*
* @event cleared
*/
@Event()
public cleared: EmitType<ClearedEventArgs>;
/**
* Triggers when the Calendar is navigated to another view or within the same level of view.
*
* @event navigated
* @blazorProperty 'Navigated'
*/
@Event()
public navigated: EmitType<NavigatedEventArgs>;
/**
* Triggers when each day cell of the Calendar is rendered.
*
* @event renderDayCell
* @blazorProperty 'OnRenderDayCell'
*/
@Event()
public renderDayCell: EmitType<RenderDayCellEventArgs>;
/**
* Gets or sets the start date of the date range selection.
*
* @default null
* @isBlazorNullableType true
*/
@Property(null)
public startDate: Date;
/**
* Gets or sets the end date of the date range selection.
*
* @default null
* @isBlazorNullableType true
*/
@Property(null)
public endDate: Date;
/**
* Set the predefined ranges which let the user pick required range easily in a component.
* > For more details refer to
* [`Preset Ranges`](../../daterangepicker/customization#preset-ranges) documentation.
* {% codeBlock src='daterangepicker/presets/index.md' %}{% endcodeBlock %}
*
* @default null
*/
@Collection<PresetsModel>([{}], Presets)
public presets: PresetsModel[];
/**
* Specifies the width of the DateRangePicker component.
*
* @default ''
*/
@Property('')
public width: number | string;
/**
* specifies the z-index value of the dateRangePicker popup element.
*
* @default 1000
* @aspType int
* @blazorType int
*/
@Property(1000)
public zIndex: number;
/**
* Specifies whether to show or hide the clear icon
*
* @default true
*/
@Property(true)
public showClearButton: boolean;
/**
* Specifies whether the today button is to be displayed or not.
*
* @default true
* @hidden
*/
@Property(true)
public showTodayButton: boolean;
/**
* Specifies the initial view of the Calendar when it is opened.
* With the help of this property, initial view can be changed to year or decade view.
*
* @default Month
*/
@Property('Month')
public start: CalendarView;
/**
* Sets the maximum level of view (month, year, decade) in the Calendar.
* Depth view should be smaller than the start view to restrict its view navigation.
*
* @default Month
*/
@Property('Month')
public depth: CalendarView;
/**
* Sets the root CSS class to the DateRangePicker which allows you to customize the appearance.
*
* @default ''
*/
@Property('')
public cssClass: string;
/**
* Sets or gets the string that used between the start and end date string.
*
* @default '-'
*/
@Property('-')
public separator: string;
/**
* Specifies the minimum span of days that can be allowed in date range selection.
* > For more details refer to
* [`Range Span`](../../daterangepicker/range-restriction/#range-span) documentation.
*
* @default null
* @aspType int
* @blazorType int
*/
@Property(null)
public minDays: number;
/**
* Specifies the maximum span of days that can be allowed in a date range selection.
* > For more details refer to
* [`Range Span`](../../daterangepicker/range-restriction/#range-span) documentation.
*
* @default null
* @aspType int
* @blazorType int
* @isBlazorNullableType true
*/
@Property(null)
public maxDays: number;
/**
* Specifies the component to act as strict which allows entering only a valid date range in a DateRangePicker.
* > For more details refer to
* [`Strict Mode`](../../daterangepicker/range-restriction#strict-mode)documentation.
*
* @default false
*/
@Property(false)
public strictMode: boolean;
/**
* Customizes the key actions in DateRangePicker.
* For example, when using German keyboard, the key actions can be customized using these shortcuts.
*
*
* Input Navigation
* <table>
* <tr>
* <td colSpan=1 rowSpan=1>
* Key action<br/></td><td colSpan=1 rowSpan=1>
* Key<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altUpArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+uparrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altDownArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+downarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* escape<br/></td><td colSpan=1 rowSpan=1>
* escape<br/></td></tr>
* </table>
*
* Calendar Navigation (Use the following list of keys to navigate the currently focused Calendar after the popup has opened).
* <table>
* <tr>
* <td colSpan=1 rowSpan=1>
* Key action<br/></td><td colSpan=1 rowSpan=1>
* Key<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* controlUp<br/></td><td colSpan=1 rowSpan=1>
* ctrl+38<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* controlDown<br/></td><td colSpan=1 rowSpan=1>
* ctrl+40<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* moveDown<br/></td><td colSpan=1 rowSpan=1>
* downarrow<br/></td></tr>
* <td colSpan=1 rowSpan=1>
* pageUp<br/></td><td colSpan=1 rowSpan=1>
* pageup<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* pageDown<br/></td><td colSpan=1 rowSpan=1>
* pagedown<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* shiftPageUp<br/></td><td colSpan=1 rowSpan=1>
* shift+pageup<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* shiftPageDown<br/></td><td colSpan=1 rowSpan=1>
* shift+pagedown<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* moveUp<br/></td><td colSpan=1 rowSpan=1>
* uparrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* moveLeft<br/></td><td colSpan=1 rowSpan=1>
* leftarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* moveRight<br/></td><td colSpan=1 rowSpan=1>
* rightarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* select<br/></td><td colSpan=1 rowSpan=1>
* enter<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* home<br/></td><td colSpan=1 rowSpan=1>
* home<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* end<br/></td><td colSpan=1 rowSpan=1>
* end<br/></td></tr>
* <tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* controlHome<br/></td><td colSpan=1 rowSpan=1>
* ctrl+home<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* controlEnd<br/></td><td colSpan=1 rowSpan=1>
* ctrl+end<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altUpArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+uparrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* spacebar<br/></td><td colSpan=1 rowSpan=1>
* space<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* enter<br/></td><td colSpan=1 rowSpan=1>
* enter<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altRightArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+rightarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altLeftArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+leftarrow<br/></td></tr>
* </table>
*
* {% codeBlock src='daterangepicker/keyConfigs/index.md' %}{% endcodeBlock %}
*
* @default null
* @blazorType object
*/
@Property(null)
public keyConfigs: { [key: string]: string };
/**
* Sets or gets the required date format to the start and end date string.
* > For more details refer to
* [`Format`](https://ej2.syncfusion.com/demos/#/material/daterangepicker/format.html)sample.
*
* @aspType string
* {% codeBlock src='daterangepicker/format/index.md' %}{% endcodeBlock %}
* @default null
* @blazorType string
*/
@Property(null)
public format: string | RangeFormatObject;
/**
* Specifies the component to be disabled which prevents the DateRangePicker from user interactions.
*
* @default true
*/
@Property(true)
public enabled: boolean;
/**
* Denies the editing the ranges in the DateRangePicker component.
*
* @default false
*/
@Property(false)
public readonly: boolean;
/**
* > Support for `allowEdit` has been provided from
* [`v16.2.46`](https://ej2.syncfusion.com/angular/documentation/release-notes/16.2.46/#daterangepicker).
*
* Specifies whether the input textbox is editable or not. Here the user can select the value from the
* popup and cannot edit in the input textbox.
*
* @default true
*/
@Property(true)
public allowEdit: boolean;
/**
* Specifies the placeholder text to be floated.
* Possible values are:
* Never: The label will never float in the input when the placeholder is available.
* Always: The floating label will always float above the input.
* Auto: The floating label will float above the input after focusing or entering a value in the input.
*
* @default Syncfusion.EJ2.Inputs.FloatLabelType.Never
* @aspType Syncfusion.EJ2.Inputs.FloatLabelType
* @blazorType Syncfusion.Blazor.Inputs.FloatLabelType
* @isEnumeration true
*/
@Property('Never')
public floatLabelType: FloatLabelType | string;
/**
* Specifies the placeholder text that need to be displayed in the DateRangePicker component.
*
* @default null
*/
@Property(null)
public placeholder: string;
/**
* You can add the additional html attributes such as disabled, value etc., to the element.
* If you configured both property and equivalent html attribute then the component considers the property value.
* {% codeBlock src='daterangepicker/htmlAttributes/index.md' %}{% endcodeBlock %}
*
* @default {}
*/
@Property({})
public htmlAttributes: { [key: string]: string };
/**
* Triggers when the DateRangePicker is opened.
*
* @event open
* @blazorProperty 'OnOpen'
* @blazorType RangePopupEventArgs
*/
@Event()
public open: EmitType<Object>;
/**
* Triggers when the DateRangePicker is closed.
*
* @event close
* @blazorProperty 'OnClose'
* @blazorType RangePopupEventArgs
*/
@Event()
public close: EmitType<Object>;
/**
* Triggers on selecting the start and end date.
*
* @event select
* @blazorProperty 'RangeSelected'
* @blazorType RangeEventArgs
*/
@Event()
public select: EmitType<Object>;
/**
* Triggers when the control gets focus.
*
* @event focus
*/
@Event()
public focus: EmitType<FocusEventArgs>;
/**
* Triggers when the control loses the focus.
*
* @event blur
*/
@Event()
public blur: EmitType<BlurEventArgs>;
/**
* Constructor for creating the widget
*
* @param {DateRangePickerModel} options - Specifies the DateRangePicker model.
* @param {string | HTMLInputElement} element - Specifies the element to render as component.
* @private
*/
public constructor(options?: DateRangePickerModel, element?: string | HTMLInputElement) {
super(options, element);
this.dateRangeOptions = options;
}
/**
* To Initialize the control rendering.
*
* @returns {void}
* @private
*/
protected render(): void {
this.initialize();
this.setProperties({ startDate: this.startValue }, true);
this.setProperties({ endDate: this.endValue }, true);
this.setModelValue();
this.setDataAttribute(false);
if (this.element.hasAttribute('data-val')) {
this.element.setAttribute('data-val', 'false');
}
this.renderComplete();
}
/**
* Initialize the event handler
*
* @returns {void}
* @private
*/
protected preRender(): void {
this.keyInputConfigs = {
altDownArrow: 'alt+downarrow',
escape: 'escape',
enter: 'enter',
tab: 'tab',
altRightArrow: 'alt+rightarrow',
altLeftArrow: 'alt+leftarrow',
moveUp: 'uparrow',
moveDown: 'downarrow',
spacebar: 'space'
};
this.defaultConstant = {
placeholder: this.placeholder,
startLabel: 'Start Date',
endLabel: 'End Date',
customRange: 'Custom Range',
applyText: 'Apply',
cancelText: 'Cancel',
selectedDays: 'Selected Days',
days: 'days'
};
/**
* Mobile View
*/
this.isMobile = window.matchMedia('(max-width:550px)').matches;
this.inputElement = <HTMLInputElement>this.element;
this.angularTag = null;
if (this.element.tagName === 'EJS-DATERANGEPICKER') {
this.angularTag = this.element.tagName;
this.inputElement = <HTMLInputElement>this.createElement('input');
this.element.appendChild(this.inputElement);
}
this.cloneElement = <HTMLElement>this.element.cloneNode(true);
removeClass([this.cloneElement], [ROOT, CONTROL, LIBRARY]);
this.updateHtmlAttributeToElement();
if (this.element.getAttribute('id')) {
if (this.angularTag !== null) {
this.inputElement.id = this.element.getAttribute('id') + '_input';
}
} else {
this.element.id = getUniqueID('ej2-datetimepicker');
if (this.angularTag !== null) {
attributes(this.inputElement, { 'id': this.element.id + '_input' });
}
}
this.checkInvalidRange(this.value);
if (!this.invalidValueString && (typeof (this.value) === 'string')) {
const rangeArray: string[] = (<string>this.value).split(' ' + this.separator + ' ');
this.value = [new Date(rangeArray[0]), new Date(rangeArray[1])];
}
this.initProperty();
this.tabIndex = this.element.hasAttribute('tabindex') ? this.element.getAttribute('tabindex') : '0';
this.element.removeAttribute('tabindex');
super.preRender();
this.navNextFunction = this.navNextMonth.bind(this);
this.navPrevFunction = this.navPrevMonth.bind(this);
this.deviceNavNextFunction = this.deviceNavNext.bind(this);
this.deviceNavPrevFunction = this.deviceNavPrevious.bind(this);
this.initStartDate = this.checkDateValue(this.startValue);
this.initEndDate = this.checkDateValue(this.endValue);
this.formElement = closest(this.element, 'form');
}
private updateValue(): void {
if (this.value && (<Date[]>this.value).length > 0) {
if ((<Date[]>this.value)[0] instanceof Date && !isNaN(+(<Date[]>this.value)[0])) {
this.setProperties({ startDate: (<Date[]>this.value)[0] }, true);
this.startValue = (<Date[]>this.value)[0];
} else if (typeof (<Date[]>this.value)[0] === 'string') {
if (+(<Date[]>this.value)[0] === 0 || isNaN(+(new Date(this.checkValue((<Date[]>this.value)[0]))))) {
this.startValue = null;
this.setValue();
} else {
this.setProperties({ startDate: new Date(this.checkValue((<Date[]>this.value)[0])) }, true);
this.startValue = new Date(this.checkValue((<Date[]>this.value)[0]));
}
} else {
this.startValue = null;
this.setValue();
}
if ((<Date[]>this.value)[1] instanceof Date && !isNaN(+(<Date[]>this.value)[1])) {
this.setProperties({ endDate: (<Date[]>this.value)[1] }, true);
this.endValue = (<Date[]>this.value)[1];
} else if (typeof (<Date[]>this.value)[1] === 'string') {
if (+(<Date[]>this.value)[0] === 0 || isNaN(+(new Date(this.checkValue((<Date[]>this.value)[0]))))) {
this.setProperties({ endDate: null }, true);
this.endValue = null;
this.setValue();
} else {
this.setProperties({ endDate: new Date(this.checkValue((<Date[]>this.value)[1])) }, true);
this.endValue = new Date(this.checkValue((<Date[]>this.value)[1]));
this.setValue();
}
} else {
this.setProperties({ endDate: null }, true);
this.endValue = null;
this.setValue();
}
} else if (this.value && (<DateRange>this.value).start) {
if ((<DateRange>this.value).start instanceof Date && !isNaN(+(<DateRange>this.value).start)) {
this.setProperties({ startDate: (<DateRange>this.value).start }, true);
this.startValue = (<DateRange>this.value).start;
} else if (typeof (<DateRange>this.value).start === 'string') {
this.setProperties({ startDate: new Date(this.checkValue((<DateRange>this.value).start)) }, true);
this.startValue = new Date(this.checkValue((<DateRange>this.value).start));
} else {
this.startValue = null;
this.setValue();
}
if ((<DateRange>this.value).end instanceof Date && !isNaN(+(<DateRange>this.value).end)) {
this.setProperties({ endDate: (<DateRange>this.value).end }, true);
this.endValue = (<DateRange>this.value).end;
} else if (typeof (<DateRange>this.value).end === 'string') {
this.setProperties({ endDate: new Date(this.checkValue((<DateRange>this.value).end)) }, true);
this.endValue = new Date(this.checkValue((<DateRange>this.value).end));
this.setValue();
} else {
this.setProperties({ endDate: null }, true);
this.endValue = null;
this.setValue();
}
} else if (isNullOrUndefined(this.value)) {
this.endValue = this.checkDateValue(new Date(this.checkValue(this.endDate)));
this.startValue = this.checkDateValue(new Date(this.checkValue(this.startDate)));
this.setValue();
}
}
private initProperty(): void {
this.globalize = new Internationalization(this.locale);
this.checkFormat();
this.checkView();
if (isNullOrUndefined(this.firstDayOfWeek) || this.firstDayOfWeek > 6 || this.firstDayOfWeek < 0) {
this.setProperties({ firstDayOfWeek: this.globalize.getFirstDayOfWeek() }, true);
}
this.updateValue();
}
protected checkFormat(): void {
if (this.format) {
if (typeof this.format === 'string') {
this.formatString = this.format;
} else if (this.format.skeleton !== '' && !isNullOrUndefined(this.format.skeleton)) {
const skeletonString: string = this.format.skeleton;
this.formatString = this.globalize.getDatePattern({ skeleton: skeletonString, type: 'date' });
} else {
this.formatString = null;
}
} else {
this.formatString = null;
}
}
private initialize(): void {
if (this.angularTag !== null) {
this.validationAttribute(this.element, this.inputElement);
}
this.checkHtmlAttributes(false);
merge(this.defaultKeyConfigs, { shiftTab: 'shift+tab' });
const start: Date = this.checkDateValue(new Date(this.checkValue(this.startValue)));
this.setProperties({ startDate: start }, true); // persist the value propeerty.
this.setProperties({ endValue: this.checkDateValue(new Date(this.checkValue(this.endValue))) }, true);
this.setValue();
this.setProperties({ min: this.checkDateValue(new Date(this.checkValue(this.min))) }, true);
this.setProperties({ max: this.checkDateValue(new Date(this.checkValue(this.max))) }, true);
this.l10n = new L10n('daterangepicker', this.defaultConstant, this.locale);
this.l10n.setLocale(this.locale);
this.setProperties({ placeholder: this.placeholder || this.l10n.getConstant('placeholder') }, true);
this.processPresets();
this.createInput();
this.updateHtmlAttributeToWrapper();
this.setRangeAllowEdit();
this.bindEvents();
}
private setDataAttribute(isDynamic: boolean) : void {
let attributes: { [key: string]: string } = {};
if (!isDynamic) {
for (let i: number = 0; i < this.element.attributes.length; i++) {
attributes[this.element.attributes[i].name] = this.element.getAttribute(this.element.attributes[i].name);
}
} else {
attributes = this.htmlAttributes;
}
for (const pro of Object.keys(attributes)) {
if (pro.indexOf('data') === 0 ) {
this.firstHiddenChild.setAttribute(pro, attributes[pro]);
this.secondHiddenChild.setAttribute(pro, attributes[pro]);
}
}
}
private setRangeAllowEdit(): void {
if (this.allowEdit) {
if (!this.readonly) {
this.inputElement.removeAttribute('readonly');
}
} else {
attributes(this.inputElement, { 'readonly': '' });
}
this.updateClearIconState();
}
private updateClearIconState(): void {
if (!this.allowEdit && this.inputWrapper && !this.readonly) {
if (this.inputElement.value === '') {
removeClass([this.inputWrapper.container], [NONEDITABLE]);
} else {
addClass([this.inputWrapper.container], [NONEDITABLE]);
}
} else if (this.inputWrapper) {
removeClass([this.inputWrapper.container], [NONEDITABLE]);
}
}
protected validationAttribute(element: HTMLElement, input: Element): void {
const name: string = element.getAttribute('name') ? element.getAttribute('name') : element.getAttribute('id');
input.setAttribute('name', name);
element.removeAttribute('name');
const attributes: string[] = ['required', 'aria-required', 'form'];
for (let i: number = 0; i < attributes.length; i++) {
if (isNullOrUndefined(element.getAttribute(attributes[i]))) {
continue;
}
const attr: string = element.getAttribute(attributes[i]);
input.setAttribute(attributes[i], attr);
element.removeAttribute(attributes[i]);
}
}
private updateHtmlAttributeToWrapper(): void {
if ( !isNullOrUndefined(this.htmlAttributes)) {
for (const key of Object.keys(this.htmlAttributes)) {
if (wrapperAttr.indexOf(key) > -1 ) {
if (key === 'class') {
const updatedClassValue: string = (this.htmlAttributes[key].replace(/\s+/g, ' ')).trim();
if (updatedClassValue !== '') {