Fixed #458 - Negative sign with InputNumber
parent
056e8faada
commit
2b74fb8d23
|
@ -443,9 +443,10 @@ export default {
|
||||||
let code = event.which || event.keyCode;
|
let code = event.which || event.keyCode;
|
||||||
let char = String.fromCharCode(code);
|
let char = String.fromCharCode(code);
|
||||||
const isDecimalSign = this.isDecimalSign(char);
|
const isDecimalSign = this.isDecimalSign(char);
|
||||||
|
const isMinusSign = this.isMinusSign(char);
|
||||||
|
|
||||||
if ((48 <= code && code <= 57) || this.isMinusSign(char) || isDecimalSign) {
|
if ((48 <= code && code <= 57) || isMinusSign || isDecimalSign) {
|
||||||
this.insert(event, char, isDecimalSign);
|
this.insert(event, char, { isDecimalSign, isMinusSign });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onPaste(event) {
|
onPaste(event) {
|
||||||
|
@ -474,15 +475,27 @@ export default {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
insert(event, text, isDecimalSign = false) {
|
insert(event, text, sign = {}) {
|
||||||
let selectionStart = this.$refs.input.$el.selectionStart;
|
let selectionStart = this.$refs.input.$el.selectionStart;
|
||||||
let selectionEnd = this.$refs.input.$el.selectionEnd;
|
let selectionEnd = this.$refs.input.$el.selectionEnd;
|
||||||
let inputValue = this.$refs.input.$el.value.trim();
|
let inputValue = this.$refs.input.$el.value.trim();
|
||||||
const decimalCharIndex = inputValue.search(this._decimal);
|
const decimalCharIndex = inputValue.search(this._decimal);
|
||||||
this._decimal.lastIndex = 0;
|
this._decimal.lastIndex = 0;
|
||||||
|
const minusCharIndex = inputValue.search(this._minusSign);
|
||||||
|
this._minusSign.lastIndex = 0;
|
||||||
let newValueStr;
|
let newValueStr;
|
||||||
|
|
||||||
if (isDecimalSign) {
|
if (sign.isMinusSign) {
|
||||||
|
if (selectionStart === 0) {
|
||||||
|
newValueStr = inputValue;
|
||||||
|
if (minusCharIndex === -1 || selectionEnd !== 0) {
|
||||||
|
newValueStr = this.insertText(inputValue, text, 0, selectionEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateValue(event, newValueStr, text, 'insert');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sign.isDecimalSign) {
|
||||||
if (decimalCharIndex > 0 && selectionStart === decimalCharIndex) {
|
if (decimalCharIndex > 0 && selectionStart === decimalCharIndex) {
|
||||||
this.updateValue(event, inputValue, text, 'insert');
|
this.updateValue(event, inputValue, text, 'insert');
|
||||||
}
|
}
|
||||||
|
@ -612,6 +625,10 @@ export default {
|
||||||
return this.max;
|
return this.max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value === '-') { // Minus sign
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
updateInput(value, insertedValueStr, operation) {
|
updateInput(value, insertedValueStr, operation) {
|
||||||
|
|
Loading…
Reference in New Issue