Fixed #455 - InputNumber with dynamic fraction digits doesn't work as expected

pull/463/head
mertsincan 2020-09-01 11:43:16 +03:00
parent 3b1fe8dcbd
commit 056e8faada
1 changed files with 51 additions and 11 deletions

View File

@ -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() {
@ -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');