Commit 10d29acb9720c3a833f8e9ff031df47f304eb1d5

Authored by huanghong
1 parent 14b7409b

InputNumber support null values

examples/routers/input-number.vue
... ... @@ -43,6 +43,11 @@
43 43 <div>
44 44 <InputNumber :max="1000000000" :min="1" v-model="value1" :formatter="formatter" :parser="parser" @on-change="change" style="width: 200px"></InputNumber>
45 45 <InputNumber :max="1000000000" :min="1" v-model="value2" :formatter="formatter2" :parser="parser2" @on-change="change" style="width: 200px"></InputNumber>
  46 +
  47 + <InputNumber @on-change="change" style="width: 200px"></InputNumber>
  48 +
  49 + <InputNumber v-model="valueNull" @on-change="change" style="width: 200px"></InputNumber>
  50 + <InputNumber v-model="valueNull" @on-change="change" :formatter="formatter" :parser="parser" style="width: 200px"></InputNumber>
46 51 </div>
47 52 </template>
48 53 <script>
... ... @@ -51,6 +56,7 @@
51 56 return {
52 57 value1: 1800000,
53 58 value2: 55,
  59 + valueNull:null,
54 60 formatter: (value) => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ','),
55 61 parser: (value) => value.replace(/\$\s?|(,*)/g, ''),
56 62 formatter2: (value) => `${value}%`,
... ...
src/components/input-number/input-number.vue
... ... @@ -178,7 +178,7 @@
178 178 return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
179 179 },
180 180 formatterValue () {
181   - if (this.formatter) {
  181 + if (this.formatter && this.precisionValue !== null) {
182 182 return this.formatter(this.precisionValue);
183 183 } else {
184 184 return this.precisionValue;
... ... @@ -279,6 +279,10 @@
279 279 const isEmptyString = val.length === 0;
280 280 val = Number(val);
281 281  
  282 + if(isEmptyString){
  283 + this.setValue(null);
  284 + return;
  285 + }
282 286 if (event.type == 'change'){
283 287 if (val === this.currentValue && val > min && val < max) return; // already fired change for input event
284 288 }
... ...