Skip to content

Commit

Permalink
Fixed #455 - InputNumber with dynamic fraction digits doesn't work as…
Browse files Browse the repository at this point in the history
… expected
  • Loading branch information
mertsincan committed Sep 1, 2020
1 parent 3b1fe8d commit 056e8fa
Showing 1 changed file with 51 additions and 11 deletions.
62 changes: 51 additions & 11 deletions src/components/inputnumber/InputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,40 @@ export default {
focused: false
}
},
watch: {
locale(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
localeMatcher(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
mode(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
currency(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
currencyDisplay(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
useGrouping(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
minFractionDigits(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
maxFractionDigits(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
suffix(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
},
prefix(newValue, oldValue) {
this.updateConstructParser(newValue, oldValue);
}
},
created() {
this.numberFormat = new Intl.NumberFormat(this.locale, this.getOptions());
const numerals = [...new Intl.NumberFormat(this.locale, {useGrouping: false}).format(9876543210)].reverse();
const index = new Map(numerals.map((d, i) => [d, i]));
this._numeral = new RegExp(`[${numerals.join('')}]`, 'g');
this._decimal = this.getDecimalExpression();
this._group = this.getGroupingExpression();
this._minusSign = this.getMinusSignExpression();
this._currency = this.getCurrencyExpression();
this._suffix = new RegExp(`[${this.suffix||''}]`, 'g');
this._prefix = new RegExp(`[${this.prefix||''}]`, 'g');
this._index = d => index.get(d);
this.constructParser();
},
methods: {
getOptions() {
Expand All @@ -144,6 +166,24 @@ export default {
maximumFractionDigits: this.maxFractionDigits
};
},
constructParser() {
this.numberFormat = new Intl.NumberFormat(this.locale, this.getOptions());
const numerals = [...new Intl.NumberFormat(this.locale, {useGrouping: false}).format(9876543210)].reverse();
const index = new Map(numerals.map((d, i) => [d, i]));
this._numeral = new RegExp(`[${numerals.join('')}]`, 'g');
this._decimal = this.getDecimalExpression();
this._group = this.getGroupingExpression();
this._minusSign = this.getMinusSignExpression();
this._currency = this.getCurrencyExpression();
this._suffix = new RegExp(`[${this.suffix||''}]`, 'g');
this._prefix = new RegExp(`[${this.prefix||''}]`, 'g');
this._index = d => index.get(d);
},
updateConstructParser(newValue, oldValue) {
if (newValue !== oldValue) {
this.constructParser();
}
},
getDecimalExpression() {
const formatter = new Intl.NumberFormat(this.locale, {useGrouping: false});
return new RegExp(`[${formatter.format(1.1).trim().replace(this._numeral, '')}]`, 'g');
Expand Down

0 comments on commit 056e8fa

Please sign in to comment.