Skip to content

Commit afa567b

Browse files
committed
Further improvements
1 parent 7a05e16 commit afa567b

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/components/form-input/form-input.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,6 @@ describe('form-input', () => {
416416
expect(wrapper.emitted('input').length).toEqual(1)
417417
expect(wrapper.emitted('input')[0][0]).toEqual('test')
418418

419-
expect(input.vm.localValue).toEqual('test')
420-
421419
wrapper.destroy()
422420
})
423421

src/components/form-textarea/form-textarea.spec.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,6 @@ describe('form-textarea', () => {
259259
const input = mount(BFormTextarea)
260260

261261
input.element.value = 'test'
262-
// Need to trigger an input event before change can be emitted
263-
input.trigger('input')
264-
expect(input.emitted('change')).not.toBeDefined()
265262

266263
input.trigger('change')
267264
expect(input.emitted('change')).toBeDefined()

src/mixins/form-text.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ export default {
111111
stringifyValue(value) {
112112
return isUndefined(value) || isNull(value) ? '' : String(value)
113113
},
114-
formatValue(value, evt, applyFormatter = true) {
114+
formatValue(value, evt, force = false) {
115115
value = this.stringifyValue(value)
116+
if (this.lazy && !force) {
117+
return value
118+
}
116119
// Emulate `.trim` modifier behaviour
117120
if (this.trim) {
118121
value = value.trim()
@@ -122,7 +125,7 @@ export default {
122125
const num = parseFloat(value)
123126
value = isNaN(num) ? value : num
124127
}
125-
if (applyFormatter && isFunction(this.formatter)) {
128+
if ((!this.lazyFormatter || force) && isFunction(this.formatter)) {
126129
value = this.formatter(value, evt)
127130
}
128131
return value
@@ -133,9 +136,7 @@ export default {
133136
if (!lazy) {
134137
this.$emit('update', value)
135138
}
136-
return true
137139
}
138-
return false
139140
},
140141
onInput(evt) {
141142
// `evt.target.composing` is set by Vue
@@ -145,7 +146,7 @@ export default {
145146
return
146147
}
147148
const value = evt.target.value
148-
const formattedValue = this.formatValue(value, evt, !this.lazyFormatter)
149+
const formattedValue = this.formatValue(value, evt)
149150
// Exit when the `formatter` function strictly returned `false`
150151
// or prevented the input event
151152
/* istanbul ignore next */
@@ -154,9 +155,8 @@ export default {
154155
return
155156
}
156157
this.localValue = value
157-
if (this.updateValue(formattedValue, this.lazy)) {
158-
this.$emit('input', value)
159-
}
158+
this.updateValue(formattedValue, this.lazy)
159+
this.$emit('input', formattedValue)
160160
},
161161
onChange(evt) {
162162
// `evt.target.composing` is set by Vue
@@ -175,11 +175,19 @@ export default {
175175
return
176176
}
177177
this.localValue = formattedValue
178-
if (this.updateValue(formattedValue)) {
179-
this.$emit('change', formattedValue)
180-
}
178+
this.updateValue(formattedValue, this.lazy)
179+
this.$emit('change', formattedValue)
181180
},
182181
onBlur(evt) {
182+
// Lazy v-model handling
183+
if (this.lazy || this.lazyFormatter) {
184+
const value = evt.target.value
185+
const formattedValue = this.formatValue(value, evt, true)
186+
if (formattedValue !== false) {
187+
this.localValue = formattedValue
188+
this.updateValue(formattedValue)
189+
}
190+
}
183191
// Emit native blur event
184192
this.$emit('blur', evt)
185193
},

0 commit comments

Comments
 (0)