@klippa/ngx-enhancy-forms 8.0.0 → 8.1.0

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.
@@ -1910,6 +1910,98 @@
1910
1910
  },] }
1911
1911
  ];
1912
1912
 
1913
+ var invalidTimeKey = '--invalid_time--';
1914
+ function timeValidator(control) {
1915
+ var invalid = control.value === invalidTimeKey;
1916
+ return invalid ? { date: control.value } : null;
1917
+ }
1918
+
1919
+ var HourMinuteInputComponent = /** @class */ (function (_super) {
1920
+ __extends(HourMinuteInputComponent, _super);
1921
+ function HourMinuteInputComponent() {
1922
+ var _this = _super.apply(this, __spread(arguments)) || this;
1923
+ _this.hoursTouched = false;
1924
+ _this.minutesTouched = false;
1925
+ return _this;
1926
+ }
1927
+ HourMinuteInputComponent.prototype.formatHours = function () {
1928
+ if (!stringIsSetAndFilled(this.hours)) {
1929
+ this.hours = '0';
1930
+ }
1931
+ };
1932
+ HourMinuteInputComponent.prototype.formatMinutes = function () {
1933
+ if (!stringIsSetAndFilled(this.minutes)) {
1934
+ this.minutes = '0';
1935
+ }
1936
+ };
1937
+ HourMinuteInputComponent.prototype.formatTime = function () {
1938
+ if (Number.isFinite(Number(this.hours)) && this.hours.length === 1) {
1939
+ this.hours = '0' + this.hours;
1940
+ }
1941
+ if (Number.isFinite(Number(this.minutes)) && this.minutes.length === 1) {
1942
+ this.minutes = '0' + this.minutes;
1943
+ }
1944
+ };
1945
+ HourMinuteInputComponent.prototype.writeValue = function (value) {
1946
+ if (Number.isFinite(value)) {
1947
+ this.hours = Math.floor(value / 60) + '';
1948
+ this.minutes = value % 60 + '';
1949
+ this.formatTime();
1950
+ _super.prototype.writeValue.call(this, value);
1951
+ }
1952
+ else {
1953
+ this.hours = '';
1954
+ this.minutes = '';
1955
+ _super.prototype.writeValue.call(this, invalidTimeKey);
1956
+ }
1957
+ };
1958
+ HourMinuteInputComponent.prototype.notifyNewTime = function () {
1959
+ var parsedHours = Number(this.hours);
1960
+ var parsedMinutes = Number(this.minutes);
1961
+ // when all inputs are empty
1962
+ if (!stringIsSetAndFilled(this.hours) && !stringIsSetAndFilled(this.minutes)) {
1963
+ this.setInnerValueAndNotify(null);
1964
+ return;
1965
+ }
1966
+ // if we have valid time
1967
+ if (stringIsSetAndFilled(this.hours) &&
1968
+ Number.isFinite(parsedHours) &&
1969
+ parsedHours >= 0 &&
1970
+ parsedHours <= 99 &&
1971
+ stringIsSetAndFilled(this.minutes) &&
1972
+ Number.isFinite(parsedMinutes) &&
1973
+ parsedMinutes >= 0 &&
1974
+ parsedMinutes <= 59) {
1975
+ this.setInnerValueAndNotify(parsedHours * 60 + parsedMinutes);
1976
+ return;
1977
+ }
1978
+ // all other cases, we are not in a valid state
1979
+ this.setInnerValueAndNotify(invalidTimeKey);
1980
+ };
1981
+ HourMinuteInputComponent.prototype.touchHours = function () {
1982
+ this.hoursTouched = true;
1983
+ this.determineAllTouched();
1984
+ };
1985
+ HourMinuteInputComponent.prototype.touchMinutes = function () {
1986
+ this.minutesTouched = true;
1987
+ this.determineAllTouched();
1988
+ };
1989
+ HourMinuteInputComponent.prototype.determineAllTouched = function () {
1990
+ if (this.hoursTouched && this.minutesTouched) {
1991
+ this.touch();
1992
+ }
1993
+ };
1994
+ return HourMinuteInputComponent;
1995
+ }(ValueAccessorBase));
1996
+ HourMinuteInputComponent.decorators = [
1997
+ { type: core.Component, args: [{
1998
+ selector: 'klp-form-hour-minute-input',
1999
+ template: "<div class=\"componentContainer\" [ngClass]=\"{disabled: disabled}\">\n\t<input maxlength=\"2\" placeholder=\"__\" [disabled]=\"disabled\" [(ngModel)]=\"hours\" (blur)=\"formatHours(); formatTime(); touchHours(); notifyNewTime()\" (ngModelChange)=\"notifyNewTime()\">\n\t<div class=\"divider\">:</div>\n\t<input maxlength=\"2\" placeholder=\"__\" [disabled]=\"disabled\" [(ngModel)]=\"minutes\" (blur)=\"formatMinutes(); formatTime(); touchMinutes(); notifyNewTime()\" (ngModelChange)=\"notifyNewTime()\">\n</div>\n",
2000
+ providers: [{ provide: forms.NG_VALUE_ACCESSOR, useExisting: HourMinuteInputComponent, multi: true }],
2001
+ styles: [":host{display:flex}.componentContainer{align-items:center;background:#fff;border:1px solid #e6ecf5;display:flex;flex:0 0 auto;height:42px;padding:6px .625rem}.componentContainer.disabled{background:#f9f9f9;cursor:not-allowed}.componentContainer input{border:none;color:#888da8;padding:0;text-align:center;width:20px}.componentContainer input::-moz-placeholder{color:#adadad}.componentContainer input:-ms-input-placeholder{color:#adadad}.componentContainer input::placeholder{color:#adadad}.componentContainer .divider{margin:0 .3125rem}"]
2002
+ },] }
2003
+ ];
2004
+
1913
2005
  var NgxEnhancyFormsModule = /** @class */ (function () {
1914
2006
  function NgxEnhancyFormsModule() {
1915
2007
  }
@@ -1948,6 +2040,7 @@
1948
2040
  FormSubmitButtonComponent,
1949
2041
  FormComponent,
1950
2042
  SubFormDirective,
2043
+ HourMinuteInputComponent
1951
2044
  ],
1952
2045
  exports: [
1953
2046
  ValueAccessorBase,
@@ -1973,6 +2066,7 @@
1973
2066
  FormSubmitButtonComponent,
1974
2067
  FormComponent,
1975
2068
  SubFormDirective,
2069
+ HourMinuteInputComponent
1976
2070
  ]
1977
2071
  },] }
1978
2072
  ];
@@ -2001,6 +2095,7 @@
2001
2095
  exports.FormElementComponent = FormElementComponent;
2002
2096
  exports.FormErrorComponent = FormErrorComponent;
2003
2097
  exports.FormSubmitButtonComponent = FormSubmitButtonComponent;
2098
+ exports.HourMinuteInputComponent = HourMinuteInputComponent;
2004
2099
  exports.KLP_DATE_FORMATS = KLP_DATE_FORMATS;
2005
2100
  exports.LoadingIndicatorComponent = LoadingIndicatorComponent;
2006
2101
  exports.MultipleValueAccessorBase = MultipleValueAccessorBase;