@rxdi/forms 0.7.256 → 0.7.258

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.
Files changed (2) hide show
  1. package/dist/form.group.js +25 -3
  2. package/package.json +2 -2
@@ -13,6 +13,14 @@ exports.FormGroup = void 0;
13
13
  const rxjs_1 = require("rxjs");
14
14
  const operators_1 = require("rxjs/operators");
15
15
  const form_tokens_1 = require("./form.tokens");
16
+ /** A number input holding text that is not a number yet ("-", "1e"): the
17
+ * browser reports its value as "" and `validity.badInput`. Writing any
18
+ * value into it erases what the user typed. */
19
+ function isNumberMidEntry(input) {
20
+ var _a;
21
+ const el = input;
22
+ return !!el && el.type === 'number' && !!((_a = el.validity) === null || _a === void 0 ? void 0 : _a.badInput);
23
+ }
16
24
  class FormGroup {
17
25
  constructor(value, errors) {
18
26
  this.validators = new Map();
@@ -161,7 +169,17 @@ class FormGroup {
161
169
  value = this.checked;
162
170
  }
163
171
  }
164
- if (this.type === 'number') {
172
+ if (isNumberMidEntry(this)) {
173
+ // "-", "1e", "1." ...: not a number yet. The browser reports the
174
+ // value as "" - converting that to 0 and writing it back erased
175
+ // what was typed, so "-1" could never be entered. Leave the input
176
+ // and the model alone until it is a number (or really empty).
177
+ return;
178
+ }
179
+ if (this.type === 'number' && value === '') {
180
+ // an emptied number field stays empty: it is not 0
181
+ }
182
+ else if (this.type === 'number') {
165
183
  let val = Number(value);
166
184
  const maxAttr = this.getAttribute('max');
167
185
  if (maxAttr) {
@@ -490,7 +508,9 @@ class FormGroup {
490
508
  input.value !== undefined &&
491
509
  input.type !== 'checkbox' &&
492
510
  input.type !== 'radio') {
493
- input.value = value;
511
+ if (!isNumberMidEntry(input)) {
512
+ input.value = value;
513
+ }
494
514
  }
495
515
  const values = this.value;
496
516
  values[name] = value;
@@ -523,7 +543,9 @@ class FormGroup {
523
543
  }
524
544
  }
525
545
  else {
526
- e.value = modelValue;
546
+ if (!isNumberMidEntry(e)) {
547
+ e.value = modelValue;
548
+ }
527
549
  }
528
550
  e.valueChanges = this._valueChanges.pipe((0, operators_1.map)((value) => value === null || value === void 0 ? void 0 : value[key]), (0, operators_1.distinctUntilChanged)());
529
551
  return [key, e];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/forms",
3
- "version": "0.7.256",
3
+ "version": "0.7.258",
4
4
  "main": "./dist/index.js",
5
5
  "author": "Kristiyan Tachev",
6
6
  "license": "MIT",
@@ -13,7 +13,7 @@
13
13
  "test": "echo tests"
14
14
  },
15
15
  "devDependencies": {
16
- "@rxdi/lit-html": "^0.7.255",
16
+ "@rxdi/lit-html": "^0.7.257",
17
17
  "@types/node": "^25.0.3",
18
18
  "rxjs": "^7.8.2",
19
19
  "typescript": "^5.9.3"