Skip to content

Commit 36a7cca

Browse files
pdanpdanrstoenescu
authored andcommitted
Fix qinput clear (quasarframework#1450)
* fix(QInput): clear button and invalid numeric value on blur * Add missing condition for force * Use const for value and isNumberError
1 parent 91ee808 commit 36a7cca

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/components/input/QInput.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,19 @@ export default {
248248
__setModel (val) {
249249
clearTimeout(this.timer)
250250
this.focus()
251-
this.__set(val || (this.isNumber ? null : ''))
251+
this.__set(val || (this.isNumber ? null : ''), true)
252252
},
253-
__set (e) {
253+
__set (e, force) {
254254
let val = e && e.target ? e.target.value : e
255255
256256
if (this.isNumber) {
257+
const forcedValue = val
257258
val = parseFloat(val)
258259
if (isNaN(val)) {
259260
this.isNumberError = true
261+
if (force) {
262+
this.$emit('input', forcedValue)
263+
}
260264
return
261265
}
262266
this.isNumberError = false

src/mixins/input.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ export default {
4848
__onBlur (e) {
4949
this.focused = false
5050
this.$emit('blur', e)
51-
let value = this.isNumber && this.isNumberError ? null : this.model
51+
const isNumberError = this.isNumber && this.isNumberError
52+
const value = isNumberError ? null : this.model
53+
if (isNumberError) {
54+
this.$emit('input', value)
55+
}
5256
this.$nextTick(() => {
5357
if (JSON.stringify(value) !== JSON.stringify(this.value)) {
5458
this.$emit('change', value)

0 commit comments

Comments
 (0)