@ardium-ui/ui 5.0.0-alpha.102 → 5.0.0-alpha.103
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.
|
@@ -670,10 +670,14 @@ class NumberInputModel {
|
|
|
670
670
|
}
|
|
671
671
|
setValue(v) {
|
|
672
672
|
let stringV = isNumber(v) ? String(v) : v;
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
673
|
+
if (stringV) {
|
|
674
|
+
const sep = this._ardHostCmp.decimalSeparator();
|
|
675
|
+
if (sep) {
|
|
676
|
+
// always store with dot as decimal separator for internal consistency
|
|
677
|
+
if (sep !== '.') {
|
|
678
|
+
stringV = stringV.split(sep).join('.');
|
|
679
|
+
}
|
|
680
|
+
}
|
|
677
681
|
}
|
|
678
682
|
this._value.set(stringV);
|
|
679
683
|
this._updateInputEl();
|
|
@@ -683,12 +687,23 @@ class NumberInputModel {
|
|
|
683
687
|
if (isNull(v))
|
|
684
688
|
return;
|
|
685
689
|
v = this._applyStandardConstraints(v, adjustMinMax ?? this._ardHostCmp.minMaxBehavior() === ArdNumberInputMinMaxBehavior.AdjustOnBlur);
|
|
690
|
+
// remove trailing zeros after decimal point
|
|
691
|
+
if (v.includes('.')) {
|
|
692
|
+
v = v.replace(/(\.\d*?)0+$/, '$1');
|
|
693
|
+
}
|
|
694
|
+
// remove decimal point if no digits after it
|
|
695
|
+
if (v.endsWith('.')) {
|
|
696
|
+
v = v.slice(0, -1);
|
|
697
|
+
}
|
|
698
|
+
// remove leading zeros (but keep "0" if the value is zero)
|
|
699
|
+
if (!v.match(/^0(\.\d+)?$/)) {
|
|
700
|
+
v = v.replace(/^0+/, '');
|
|
701
|
+
}
|
|
702
|
+
// apply fixed decimal places if configured
|
|
686
703
|
if (this._ardHostCmp.fixedDecimalPlaces()) {
|
|
687
704
|
v = this._fixDecimalPlaces(v);
|
|
688
705
|
}
|
|
689
|
-
|
|
690
|
-
// convert to number and back to string to remove any trailing decimal separator without digits and to remove leading zeros
|
|
691
|
-
this.setValue(Number(v));
|
|
706
|
+
this.setValue(v);
|
|
692
707
|
}
|
|
693
708
|
_fixDecimalPlaces(v) {
|
|
694
709
|
const maxDp = this._ardHostCmp.maxDecimalPlaces();
|
|
@@ -720,6 +735,9 @@ class NumberInputModel {
|
|
|
720
735
|
//normalize the value
|
|
721
736
|
v = v?.toString?.() ?? String(v);
|
|
722
737
|
}
|
|
738
|
+
// check if value is already the same as current value
|
|
739
|
+
if (v === null ? v === this._value() : Number(v) === this.numberValue())
|
|
740
|
+
return false;
|
|
723
741
|
v = v === null ? null : String(v);
|
|
724
742
|
return this._writeValue(v, applyConstraints);
|
|
725
743
|
}
|
|
@@ -10348,9 +10366,9 @@ class ArdiumNumberInputComponent extends _FormFieldComponentBase {
|
|
|
10348
10366
|
});
|
|
10349
10367
|
// refresh input display when decimalSeparator changes
|
|
10350
10368
|
effect(() => {
|
|
10351
|
-
|
|
10369
|
+
this.decimalSeparator();
|
|
10352
10370
|
// calling rewrite ensures element value includes new separator
|
|
10353
|
-
this.inputModel.rewriteValueAfterHostUpdate();
|
|
10371
|
+
untracked(() => this.inputModel.rewriteValueAfterHostUpdate());
|
|
10354
10372
|
});
|
|
10355
10373
|
}
|
|
10356
10374
|
ngAfterViewInit() {
|