@progress/kendo-dateinputs-common 0.2.0-dev.202301161405 → 0.2.0-dev.202301231327

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -547,6 +547,14 @@ var DateObject = /** @class */ (function () {
547
547
  literal: ""
548
548
  };
549
549
  });
550
+ var flatDateParts = dateParts.partMap
551
+ .map(function (x) {
552
+ return {
553
+ type: x.type,
554
+ pattern: x.pattern,
555
+ text: ""
556
+ };
557
+ });
550
558
  for (var i = 0; i < datePartsLiterals.length; i++) {
551
559
  var datePart = datePartsLiterals[i];
552
560
  for (var j = 0; j < datePart.pattern.length; j++) {
@@ -556,13 +564,23 @@ var DateObject = /** @class */ (function () {
556
564
  }
557
565
  i += datePart.pattern.length - 1;
558
566
  }
567
+ for (var i = 0; i < flatDateParts.length; i++) {
568
+ var datePart = flatDateParts[i];
569
+ for (var j = 0; j < datePart.pattern.length; j++) {
570
+ if (flatDateParts[i + j]) {
571
+ flatDateParts[i + j].text = datePart.pattern[j];
572
+ }
573
+ }
574
+ i += datePart.pattern.length - 1;
575
+ }
559
576
  var shouldResetPart = isInCaretMode && symbol === "M" && dateParts.partMap
560
577
  .filter(function (x) { return x.type === "month"; })
561
578
  .some(function (x) { return x.pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD; });
562
579
  var parseResult = {
563
580
  value: null,
564
581
  switchPart: false,
565
- resetPart: shouldResetPart
582
+ resetPart: shouldResetPart,
583
+ hasInvalidDatePart: false
566
584
  };
567
585
  if (!currentChar) {
568
586
  if (isInCaretMode) {
@@ -596,13 +614,19 @@ var DateObject = /** @class */ (function () {
596
614
  var basePrefix = '';
597
615
  var baseSuffix = '';
598
616
  var suffix = '';
599
- var datePartStartIndex = originalFormat.indexOf(symbol);
600
- var datePartEndIndex = originalFormat.lastIndexOf(symbol);
601
- var segmentLength = datePartEndIndex - datePartStartIndex + 1;
617
+ var convertedBaseFormat = "";
618
+ for (var i = 0; i < flatDateParts.length; i++) {
619
+ convertedBaseFormat += flatDateParts[i].text;
620
+ }
602
621
  var hasFixedFormat = (this.format === baseFormat) ||
622
+ (this.format === convertedBaseFormat) ||
603
623
  (this.format === originalFormat) ||
604
624
  (this.format.length === originalFormat.length);
625
+ var datePartStartIndex = (hasFixedFormat ? convertedBaseFormat : originalFormat).indexOf(symbol);
626
+ var datePartEndIndex = (hasFixedFormat ? convertedBaseFormat : originalFormat).lastIndexOf(symbol);
627
+ var segmentLength = datePartEndIndex - datePartStartIndex + 1;
605
628
  var processedSegmentCharsCount = 0;
629
+ var formatToTextLengthDiff = originalFormat.length - rawInputValue.length;
606
630
  if (isInCaretMode || (!isInCaretMode && !this.autoCorrectParts)) {
607
631
  for (var i = 0; i < baseDate.length; i++) {
608
632
  if (baseFormat[i] === symbol) {
@@ -615,6 +639,11 @@ var DateObject = /** @class */ (function () {
615
639
  }
616
640
  processedSegmentCharsCount++;
617
641
  }
642
+ else if (formatToTextLengthDiff > 0) {
643
+ if (datePartText.length + formatToTextLengthDiff < segmentLength) {
644
+ datePartText += rawInputValue[i] || "";
645
+ }
646
+ }
618
647
  else {
619
648
  datePartText += rawInputValue[i] || "";
620
649
  }
@@ -629,13 +658,13 @@ var DateObject = /** @class */ (function () {
629
658
  baseSuffix += baseDate[i];
630
659
  }
631
660
  }
632
- if (hasFixedFormat && this.autoCorrectParts) {
633
- if (originalFormat.length < rawInputValue.length) {
661
+ if (hasFixedFormat) {
662
+ if (convertedBaseFormat.length < rawInputValue.length) {
634
663
  datePartText += currentChar;
635
664
  }
636
665
  else if (!isDeleting && originalFormat.length > rawInputValue.length) {
637
666
  var lengthDiff = originalFormat.length - rawInputValue.length;
638
- var trimmedDatePartText = datePartText.substring(0, datePartText.length - lengthDiff);
667
+ var trimmedDatePartText = datePartText.substr(0, datePartText.length - lengthDiff);
639
668
  if (trimmedDatePartText && trimmedDatePartText.length > 0) {
640
669
  datePartText = trimmedDatePartText;
641
670
  }
@@ -644,7 +673,7 @@ var DateObject = /** @class */ (function () {
644
673
  return utils_2.extend(parseResult, { value: null, switchToNext: false });
645
674
  }
646
675
  }
647
- else {
676
+ if (!hasFixedFormat || (hasFixedFormat && !this.autoCorrectParts)) {
648
677
  processedSegmentCharsCount = 0;
649
678
  current = "";
650
679
  datePartText = "";
@@ -662,6 +691,11 @@ var DateObject = /** @class */ (function () {
662
691
  }
663
692
  processedSegmentCharsCount++;
664
693
  }
694
+ else if (formatToTextLengthDiff > 0) {
695
+ if (datePartText.length + formatToTextLengthDiff < segmentLength) {
696
+ datePartText += rawInputValue[i] || "";
697
+ }
698
+ }
665
699
  else {
666
700
  datePartText += rawInputValue[i] || "";
667
701
  }
@@ -671,24 +705,12 @@ var DateObject = /** @class */ (function () {
671
705
  prefix += rawInputValue[i] || "";
672
706
  }
673
707
  else {
674
- suffix += rawInputValue[i] || "";
708
+ suffix += rawInputValue[i - formatToTextLengthDiff] || "";
675
709
  }
676
710
  }
677
711
  if (originalFormat.length < rawInputValue.length) {
678
712
  datePartText += currentChar;
679
713
  }
680
- else if (!isDeleting && originalFormat.length > rawInputValue.length) {
681
- var lengthDiff = originalFormat.length - rawInputValue.length;
682
- var trimmedDatePartText = datePartText.substring(0, datePartText.length - lengthDiff);
683
- if (trimmedDatePartText && trimmedDatePartText.length > 0) {
684
- var originalDatePartText = datePartText;
685
- datePartText = trimmedDatePartText;
686
- if (prefix + datePartText + suffix !== rawInputValue) {
687
- // move trimmed characters to the suffix
688
- suffix = originalDatePartText.substring(datePartText.length) + suffix;
689
- }
690
- }
691
- }
692
714
  }
693
715
  }
694
716
  if (!isInCaretMode) {
@@ -722,8 +744,13 @@ var DateObject = /** @class */ (function () {
722
744
  var dayPeriod = this.matchDayPeriod(currentChar, symbol);
723
745
  var isZeroCurrentChar = currentChar === '0';
724
746
  var leadingZero = this.leadingZero || {};
725
- if (isZeroCurrentChar && !isInCaretMode) {
726
- var valueNumber = parseInt(resetSegmentValue ? currentChar : current + currentChar, 10);
747
+ if (isZeroCurrentChar) {
748
+ if (datePartText === "0") {
749
+ datePartText = current;
750
+ }
751
+ var valueNumber = utils_2.parseToInt(resetSegmentValue ?
752
+ currentChar :
753
+ (isInCaretMode ? datePartText : current) + currentChar);
727
754
  if (valueNumber === 0 && !this.isAbbrMonth(dateParts.partMap, symbol)) {
728
755
  this.incrementLeadingZero(symbol);
729
756
  }
@@ -751,23 +778,15 @@ var DateObject = /** @class */ (function () {
751
778
  isInCaretMode ?
752
779
  datePartText :
753
780
  (current.substring(i) + currentChar);
754
- if (!this.autoCorrectParts) {
755
- tryParse = false;
756
- if (!isInCaretMode) {
757
- // try to make an exact match as there will be only 1 attempt
758
- middle = utils_1.unpadZero(middle);
759
- middle = utils_1.padZero(segmentLength - middle.length) + middle;
760
- }
761
- }
762
- if (isInCaretMode) {
763
- // try to make an exact match as there will be only 1 attempt
781
+ if (isInCaretMode || !this.autoCorrectParts) {
764
782
  tryParse = false;
765
783
  middle = utils_1.unpadZero(middle);
784
+ middle = utils_1.padZero(segmentLength - middle.length) + middle;
766
785
  }
767
786
  var middleNumber = parseInt(middle, 10);
768
787
  var candidateDateString = prefix + middle + suffix;
769
788
  parsedDate = this.intl.parseDate(candidateDateString, this.format, this.localeId);
770
- if (isInCaretMode && !hasFixedFormat && !utils_2.isValidDate(parsedDate)) {
789
+ if (isInCaretMode && !utils_2.isValidDate(parsedDate)) {
771
790
  // if part of the date is not available, e.g. "d"
772
791
  // but an expanded format like "F" is used
773
792
  // the element value can be "EEEE, February 1, 2022 3:04:05 AM"
@@ -777,7 +796,6 @@ var DateObject = /** @class */ (function () {
777
796
  // as "EEEE, February..." is not parsable
778
797
  if (this.autoCorrectParts) {
779
798
  parsedDate = this.intl.parseDate(basePrefix + middle + baseSuffix, this.format, this.localeId);
780
- datePartText = middle;
781
799
  }
782
800
  }
783
801
  var isCurrentCharParsable = !isNaN(parseInt(currentChar, 10)) || (isInCaretMode && isDeleting && currentChar === "");
@@ -804,13 +822,10 @@ var DateObject = /** @class */ (function () {
804
822
  if ((isInCaretMode && utils_2.isValidDate(parsedDate)) || (!isInCaretMode && parsedDate)) {
805
823
  // move to next segment if the part will overflow with next char
806
824
  // when start from empty date (01, then 010), padded zeros should be trimmed
807
- var peekDate = this.intl.parseDate("" + prefix + this.peek(middle, patternValue) + suffix, this.format, this.localeId);
808
- var patternLength = this.patternLength(patternValue) || patternValue.length;
809
- var leadingZeroOffset = (this.leadingZero || {})[symbol] || 0;
810
- var patternSatisfied = (leadingZeroOffset + (utils_1.unpadZero(middle) || currentChar).length) >= patternLength;
811
- var switchToNext = peekDate === null ||
812
- (leadingZero[symbol] && patternValue.length <= middle.length) ||
813
- patternSatisfied;
825
+ var peekValue = this.peek(middle, patternValue);
826
+ var peekDateString = "" + prefix + peekValue + suffix;
827
+ var peekDate = this.intl.parseDate(peekDateString, this.format, this.localeId);
828
+ var switchToNext = peekDate === null || (leadingZero[symbol] && patternValue.length <= middle.length) || false;
814
829
  if (this.shouldNormalizeCentury()) {
815
830
  parsedDate = this.normalizeCentury(parsedDate);
816
831
  }
@@ -838,14 +853,12 @@ var DateObject = /** @class */ (function () {
838
853
  }
839
854
  if (isInCaretMode && switchToNext) {
840
855
  if (symbol === "M") {
841
- if (segmentLength <= MONTH_PART_WITH_WORDS_THRESHOLD) {
842
- var datePartValue = utils_2.parseToInt(datePartText);
843
- if (datePartValue >= 2) {
844
- switchToNext = true;
845
- }
846
- else {
847
- switchToNext = false;
848
- }
856
+ var datePartValue = utils_2.parseToInt(datePartText);
857
+ if (datePartValue >= 2 || datePartText.length >= 2) {
858
+ switchToNext = true;
859
+ }
860
+ else {
861
+ switchToNext = false;
849
862
  }
850
863
  }
851
864
  else {
@@ -878,9 +891,6 @@ var DateObject = /** @class */ (function () {
878
891
  this.leadingZero = !this.isAbbrMonth(dateParts.partMap, symbol) ? (_b = {}, _b[symbol] = true, _b) : null;
879
892
  this.setExisting(symbol, false);
880
893
  }
881
- if (isInCaretMode && datePartText.length > segmentLength) {
882
- return utils_2.extend(parseResult, { value: null, switchToNext: false });
883
- }
884
894
  if (!this.autoCorrectParts) {
885
895
  var datePartValue = void 0;
886
896
  var textToParse = isInCaretMode ? datePartText : middle;
@@ -891,20 +901,146 @@ var DateObject = /** @class */ (function () {
891
901
  return utils_2.extend(parseResult, { value: null, switchToNext: false });
892
902
  }
893
903
  datePartValue = symbol === "M" ?
894
- utils_2.clamp(parsedValue - JS_MONTH_OFFSET, 0, 12 - JS_MONTH_OFFSET) :
904
+ parsedValue - JS_MONTH_OFFSET :
895
905
  parsedValue;
896
- // if (!isEqual(newDate, this.value)) {
897
- this.setExisting(symbol, false);
898
- this.setInvalidDatePart(symbol, {
899
- value: datePartValue,
900
- date: kendo_date_math_1.cloneDate(this.value),
901
- startDate: this._partiallyInvalidDate.startDate || kendo_date_math_1.cloneDate(this.value)
902
- });
903
- // }
906
+ var isMonth = symbol === "M";
907
+ var isDay = symbol === "d";
908
+ var newValue = kendo_date_math_1.cloneDate(this._value);
909
+ var invalidDateParts = this._partiallyInvalidDate.invalidDateParts || {};
910
+ var year = invalidDateParts.y.value || newValue.getFullYear();
911
+ /* tslint:disable:no-shadowed-variable */
912
+ var month_1 = isMonth ? datePartValue : invalidDateParts.M.value || newValue.getMonth();
913
+ /* tslint:enable:no-shadowed-variable */
914
+ var day = isDay ? datePartValue : invalidDateParts.d.value || invalidDateParts.E.value || newValue.getDate();
915
+ var hour = invalidDateParts.h.value || invalidDateParts.H.value || newValue.getHours();
916
+ var minutes = invalidDateParts.m.value || newValue.getMinutes();
917
+ var seconds = invalidDateParts.s.value || newValue.getSeconds();
918
+ var milliseconds = invalidDateParts.S.value || newValue.getMilliseconds();
919
+ var dateCandidate = kendo_date_math_1.createDate(year, month_1, day, hour, minutes, seconds, milliseconds);
920
+ var dateCandidateExists = utils_2.areDatePartsEqualTo(dateCandidate, year, month_1, day, hour, minutes, seconds, milliseconds);
921
+ var newValueCandidate = isMonth || isDay ?
922
+ this.modifyDateSymbolWithValue(newValue, symbol, isMonth ? month_1 : day) :
923
+ null;
924
+ var invalidDateFound = false;
925
+ if (isMonth && newValueCandidate) {
926
+ if (newValueCandidate.getMonth() === month_1) {
927
+ if (this.getExisting("d")) {
928
+ if (dateCandidateExists) {
929
+ newValue = kendo_date_math_1.cloneDate(dateCandidate);
930
+ this.resetInvalidDateSymbol(symbol);
931
+ }
932
+ else {
933
+ invalidDateFound = true;
934
+ this.setInvalidDatePart(symbol, {
935
+ value: month_1,
936
+ date: kendo_date_math_1.cloneDate(newValueCandidate),
937
+ // startDateOffset: offset,
938
+ startDate: kendo_date_math_1.cloneDate(this.value)
939
+ });
940
+ this.setExisting(symbol, false);
941
+ }
942
+ }
943
+ else if (dateCandidateExists) {
944
+ this.resetInvalidDateSymbol(symbol);
945
+ newValue = kendo_date_math_1.cloneDate(dateCandidate);
946
+ if (this.getExisting("M") && this.getExisting("y")) {
947
+ // changing from 28/Feb to 29/Feb to 29/March
948
+ this.setExisting("d", true);
949
+ this.resetInvalidDateSymbol("d");
950
+ }
951
+ }
952
+ else {
953
+ this.resetInvalidDateSymbol(symbol);
954
+ newValue = kendo_date_math_1.cloneDate(newValueCandidate);
955
+ }
956
+ }
957
+ else {
958
+ invalidDateFound = true;
959
+ this.setInvalidDatePart(symbol, {
960
+ value: month_1,
961
+ date: kendo_date_math_1.cloneDate(newValueCandidate),
962
+ // startDateOffset: offset,
963
+ startDate: kendo_date_math_1.cloneDate(this.value)
964
+ });
965
+ this.setExisting(symbol, false);
966
+ }
967
+ }
968
+ else if (isDay && newValueCandidate) {
969
+ if (newValueCandidate.getDate() === day) {
970
+ if (this.getExisting("M")) {
971
+ if (dateCandidateExists) {
972
+ newValue = kendo_date_math_1.cloneDate(dateCandidate);
973
+ this.resetInvalidDateSymbol(symbol);
974
+ }
975
+ else {
976
+ invalidDateFound = true;
977
+ this.setInvalidDatePart(symbol, {
978
+ value: day,
979
+ date: kendo_date_math_1.cloneDate(newValueCandidate),
980
+ // startDateOffset: offset,
981
+ startDate: kendo_date_math_1.cloneDate(this.value)
982
+ });
983
+ this.setExisting(symbol, false);
984
+ }
985
+ }
986
+ else if (dateCandidateExists) {
987
+ newValue = kendo_date_math_1.cloneDate(dateCandidate);
988
+ this.resetInvalidDateSymbol(symbol);
989
+ if (this.getExisting("d") && this.getExisting("y")) {
990
+ // changing from 31/Jan to 31/Feb to 28/Feb
991
+ this.setExisting("M", true);
992
+ this.resetInvalidDateSymbol("M");
993
+ }
994
+ }
995
+ else {
996
+ this.resetInvalidDateSymbol(symbol);
997
+ newValue = kendo_date_math_1.cloneDate(newValueCandidate);
998
+ }
999
+ }
1000
+ else {
1001
+ invalidDateFound = true;
1002
+ this.setInvalidDatePart(symbol, {
1003
+ value: day,
1004
+ date: kendo_date_math_1.cloneDate(this.value),
1005
+ // startDateOffset: offset,
1006
+ startDate: kendo_date_math_1.cloneDate(this.value)
1007
+ });
1008
+ this.setExisting(symbol, false);
1009
+ }
1010
+ }
1011
+ if (!invalidDateFound) {
1012
+ this.setExisting(symbol, true);
1013
+ if (isInCaretMode && !utils_2.isValidDate(parsedDate)) {
1014
+ var valueCandidate = this.intl.parseDate(basePrefix + middle + baseSuffix, this.format, this.localeId);
1015
+ if (utils_2.isValidDate(valueCandidate)) {
1016
+ this._value = valueCandidate;
1017
+ }
1018
+ }
1019
+ else {
1020
+ this._value = newValue;
1021
+ }
1022
+ if (this.getValue()) {
1023
+ this.resetInvalidDate();
1024
+ }
1025
+ }
1026
+ var switchToNext = false;
1027
+ if (symbol === "M") {
1028
+ if (parsedValue >= 2 || textToParse.length >= 2) {
1029
+ switchToNext = true;
1030
+ }
1031
+ else {
1032
+ switchToNext = false;
1033
+ }
1034
+ }
1035
+ else {
1036
+ switchToNext = hasFixedFormat ?
1037
+ textToParse.length === segmentLength :
1038
+ textToParse.length > segmentLength;
1039
+ }
904
1040
  return utils_2.extend(parseResult, {
905
1041
  value: null,
906
- switchToNext: false,
907
- hasInvalidDatePart: true
1042
+ switchToNext: switchToNext,
1043
+ hasInvalidDatePart: invalidDateFound
908
1044
  });
909
1045
  }
910
1046
  }
@@ -927,6 +1063,12 @@ var DateObject = /** @class */ (function () {
927
1063
  DateObject.prototype.setLeadingZero = function (leadingZero) {
928
1064
  this.leadingZero = leadingZero;
929
1065
  };
1066
+ /**
1067
+ * @hidden
1068
+ */
1069
+ DateObject.prototype.getLeadingZero = function () {
1070
+ return this.leadingZero || {};
1071
+ };
930
1072
  /**
931
1073
  * @hidden
932
1074
  */
@@ -1010,7 +1152,6 @@ var DateObject = /** @class */ (function () {
1010
1152
  var dateFormatParts = this.intl.splitDateFormat(this.format, this.localeId);
1011
1153
  for (var i = 0; i < dateFormatParts.length; i++) {
1012
1154
  if (dateFormatParts[i].type === 'month' && dateFormatParts[i].names) {
1013
- // return this.intl.dateFormatNames(dateFormatParts[i].names);
1014
1155
  return this.intl.dateFormatNames(locale, dateFormatParts[i].names);
1015
1156
  }
1016
1157
  }
@@ -1222,15 +1363,8 @@ var DateObject = /** @class */ (function () {
1222
1363
  };
1223
1364
  DateObject.prototype.setInvalidDatePart = function (symbol, _a) {
1224
1365
  var _b = _a.value, value = _b === void 0 ? null : _b, _c = _a.date, date = _c === void 0 ? null : _c, _d = _a.startDateOffset, startDateOffset = _d === void 0 ? 0 : _d, _e = _a.startDate, startDate = _e === void 0 ? null : _e;
1225
- var clampedValue = value;
1226
- if (symbol === "d") {
1227
- clampedValue = utils_2.clamp(utils_2.isPresent(value) ? value : 1, 1, 31);
1228
- }
1229
- else if (symbol === "M") {
1230
- clampedValue = utils_2.clamp(utils_2.isPresent(value) ? value : 0, 0, 11);
1231
- }
1232
1366
  if (this._partiallyInvalidDate.invalidDateParts[symbol]) {
1233
- this._partiallyInvalidDate.invalidDateParts[symbol].value = clampedValue;
1367
+ this._partiallyInvalidDate.invalidDateParts[symbol].value = value;
1234
1368
  this._partiallyInvalidDate.invalidDateParts[symbol].date = date;
1235
1369
  this._partiallyInvalidDate.invalidDateParts[symbol].startDateOffset = startDateOffset;
1236
1370
  this._partiallyInvalidDate.startDate = startDate;
@@ -9,6 +9,7 @@ export declare class DateInput extends Observable {
9
9
  private resetSegmentValue;
10
10
  private isActive;
11
11
  private interactionMode;
12
+ private formatStateOnKeyDown;
12
13
  private previousElementValue;
13
14
  private previousElementSelection;
14
15
  private keyDownEvent;
@@ -33,6 +33,7 @@ var CHANGE = "change";
33
33
  var defaultDateInputOptions = {
34
34
  format: "d",
35
35
  allowNulls: false,
36
+ hasPlaceholder: false,
36
37
  placeholder: null,
37
38
  cycleTime: true,
38
39
  locale: null,
@@ -305,6 +306,24 @@ var DateInput = /** @class */ (function (_super) {
305
306
  isInCaretMode: hasCaret,
306
307
  keyEvent: this.keyDownEvent
307
308
  });
309
+ var currentFormatChar = this.formatStateOnKeyDown.format[this.formatStateOnKeyDown.selectionStart] || "";
310
+ if (this.options.allowCaretMode && hasCaret && this.currentFormat.length !== this.elementValue.length) {
311
+ if (currentFormatChar &&
312
+ currentFormatChar.length > 0 &&
313
+ currentFormatChar !== constants_1.Constants.formatSeparator) {
314
+ if (!diff || diff.length === 0) {
315
+ diff = [];
316
+ diff[0][0] = currentFormatChar;
317
+ diff[0][1] = e.data || "";
318
+ }
319
+ else if (diff[0] && diff[0][0] !== constants_1.Constants.formatSeparator) {
320
+ if (diff[0][0] !== currentFormatChar) {
321
+ diff[0][0] = currentFormatChar;
322
+ diff[0][1] = e.data || "";
323
+ }
324
+ }
325
+ }
326
+ }
308
327
  if (hasCaret && (!diff || diff.length === 0)) {
309
328
  this.restorePreviousInputEventState();
310
329
  return;
@@ -377,10 +396,30 @@ var DateInput = /** @class */ (function (_super) {
377
396
  if (switchPart) {
378
397
  this.switchDateSegment(1);
379
398
  }
399
+ else {
400
+ if (this.options.format.length !== this.currentFormat.length &&
401
+ currentFormatChar && currentFormatChar !== "y") {
402
+ var elementValueLength = this.elementValue.length;
403
+ this.forceUpdate();
404
+ var selectionOffset = this.elementValue.length - elementValueLength;
405
+ this.setSelection({
406
+ start: currentSelection.start + selectionOffset,
407
+ end: currentSelection.start + selectionOffset
408
+ });
409
+ }
410
+ }
380
411
  }
381
412
  else {
382
- if (lastParseResultHasNoValue && !hasInvalidDatePart) {
383
- this.restorePreviousInputEventState();
413
+ if (lastParseResultHasNoValue) {
414
+ var hasLeadingZero = this.dateObject.getLeadingZero()[currentFormatChar];
415
+ if (switchPart) {
416
+ this.switchDateSegment(1);
417
+ }
418
+ else if (e.data === "0" && hasLeadingZero) {
419
+ }
420
+ else {
421
+ this.restorePreviousInputEventState();
422
+ }
384
423
  }
385
424
  }
386
425
  }
@@ -405,7 +444,10 @@ var DateInput = /** @class */ (function (_super) {
405
444
  }
406
445
  }
407
446
  else {
408
- if (!hasInvalidDatePart) {
447
+ var hasLeadingZero = this.dateObject.getLeadingZero()[currentFormatChar];
448
+ if (e.data === "0" && hasLeadingZero) {
449
+ }
450
+ else if (!hasInvalidDatePart) {
409
451
  this.restorePreviousInputEventState();
410
452
  }
411
453
  }
@@ -469,9 +511,14 @@ var DateInput = /** @class */ (function (_super) {
469
511
  if (this.triggerKeyDown({ event: e })) {
470
512
  return;
471
513
  }
514
+ var _a = this.selection, start = _a.start, end = _a.end;
472
515
  this.keyDownEvent = e;
473
516
  this.previousElementValue = this.element.value;
474
- var _a = this.selection, start = _a.start, end = _a.end;
517
+ this.formatStateOnKeyDown = {
518
+ format: this.currentFormat,
519
+ selectionStart: start,
520
+ selectionEnd: end
521
+ };
475
522
  this.previousElementSelection = { start: start, end: end };
476
523
  var autoSwitchKeys = (this.options.autoSwitchKeys || [])
477
524
  .map(function (x) { return x.toString().toLowerCase().trim(); });
@@ -741,11 +788,13 @@ var DateInput = /** @class */ (function (_super) {
741
788
  return;
742
789
  }
743
790
  }
791
+ this.interactionMode = interaction_mode_1.DateInputInteractionMode.None;
744
792
  var _a = this.selection, selectionStart = _a.start, selectionEnd = _a.end;
745
793
  if (selectionStart < selectionEnd &&
746
794
  this.currentFormat[selectionStart] !== this.currentFormat[selectionEnd - 1]) {
747
795
  this.setSelection(this.selectionByIndex(offset > 0 ? selectionStart : selectionEnd - 1));
748
796
  this.resetSegmentValue = true;
797
+ this.interactionMode = interaction_mode_1.DateInputInteractionMode.None;
749
798
  return;
750
799
  }
751
800
  var previousFormatSymbol = this.currentFormat[selectionStart];
@@ -776,6 +825,7 @@ var DateInput = /** @class */ (function (_super) {
776
825
  this.setSelection({ start: a, end: b });
777
826
  this.resetSegmentValue = true;
778
827
  }
828
+ this.interactionMode = interaction_mode_1.DateInputInteractionMode.None;
779
829
  };
780
830
  DateInput.prototype.modifyDateSegmentValue = function (offset, symbol, event) {
781
831
  if (symbol === void 0) { symbol = ""; }
@@ -977,13 +1027,14 @@ var DateInput = /** @class */ (function (_super) {
977
1027
  var _a = this.dateObject.getTextAndFormat(format), currentText = _a.text, currentFormat = _a.format;
978
1028
  this.currentFormat = currentFormat;
979
1029
  this.currentText = currentText;
1030
+ var hasPlaceholder = this.options.hasPlaceholder || utils_2.isPresent(this.options.placeholder);
980
1031
  var showPlaceholder = !this.isActive &&
981
- utils_2.isPresent(this.options.placeholder) &&
1032
+ hasPlaceholder &&
982
1033
  !this.dateObject.hasValue();
983
- if (utils_2.isPresent(this.options.placeholder)) {
1034
+ if (hasPlaceholder && utils_2.isPresent(this.options.placeholder)) {
984
1035
  element.placeholder = this.options.placeholder;
985
1036
  }
986
- var newElementValue = !showPlaceholder ? currentText : "";
1037
+ var newElementValue = showPlaceholder ? "" : currentText;
987
1038
  this.previousElementValue = this.elementValue;
988
1039
  this.setElementValue(newElementValue);
989
1040
  if (this.isActive && !this.options.allowCaretMode && this.options.selectNearestSegmentOnFocus) {