Merge pull request #2059 from SergioCrisostomo/add-input-event

fire change on "input" event
This commit is contained in:
Aresn 2017-10-11 04:56:24 -05:00 committed by GitHub
commit 9ca05a64da

View file

@ -24,6 +24,7 @@
@focus="focus" @focus="focus"
@blur="blur" @blur="blur"
@keydown.stop="keyDown" @keydown.stop="keyDown"
@input="change"
@change="change" @change="change"
:readonly="readonly || !editable" :readonly="readonly || !editable"
:name="name" :name="name"
@ -38,9 +39,6 @@
const prefixCls = 'ivu-input-number'; const prefixCls = 'ivu-input-number';
const iconPrefixCls = 'ivu-icon'; const iconPrefixCls = 'ivu-icon';
function isValueNumber (value) {
return (/(^-?[0-9]+\.{1}\d+$)|(^-?[1-9][0-9]*$)|(^-?0{1}$)/).test(value + '');
}
function addNum (num1, num2) { function addNum (num1, num2) {
let sq1, sq2, m; let sq1, sq2, m;
try { try {
@ -256,11 +254,13 @@
change (event) { change (event) {
let val = event.target.value.trim(); let val = event.target.value.trim();
const max = this.max; if (event.type == 'input' && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later
const min = this.min; if (event.type == 'change' && Number(val) === this.currentValue) return; // already fired change for input event
if (isValueNumber(val)) { const {min, max} = this;
const isEmptyString = val.length === 0;
val = Number(val); val = Number(val);
if (!isNaN(val) && !isEmptyString) {
this.currentValue = val; this.currentValue = val;
if (val > max) { if (val > max) {
@ -275,8 +275,8 @@
} }
}, },
changeVal (val) { changeVal (val) {
if (isValueNumber(val) || val === 0) {
val = Number(val); val = Number(val);
if (!isNaN(val)) {
const step = this.step; const step = this.step;
this.upDisabled = val + step > this.max; this.upDisabled = val + step > this.max;