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