Skip to content

Commit

Permalink
fix: Allow text fields to have an initial value of 0
Browse files Browse the repository at this point in the history
Every time maskText was called, it had an attempted null check: || ''
This check meant that any falsy values would get converted into
an empty string.
I removed all these checks and replaced them with a proper one
in mask.js@maskText()

Fixes vuetifyjs#2136
  • Loading branch information
KaelWD committed Oct 11, 2017
1 parent 2d0cf35 commit 95b7f83
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/VTextField/VTextField.js
Expand Up @@ -182,7 +182,7 @@ export default {
autofocus: this.autofocus,
disabled: this.disabled,
required: this.required,
value: this.maskText(this.lazyValue || '')
value: this.maskText(this.lazyValue)
},
attrs: {
...this.$attrs,
Expand Down
8 changes: 8 additions & 0 deletions src/components/VTextField/VTextField.spec.js
Expand Up @@ -331,4 +331,12 @@ test('VTextField.js', ({ mount }) => {

expect(wrapper.html()).toMatchSnapshot()
})

it('should display the number 0', async () => {
const wrapper = mount(VTextField, {
propsData: { value: 0 }
})

expect(wrapper.vm.$refs.input.value).toBe('0')
})
})
4 changes: 2 additions & 2 deletions src/mixins/maskable.js
Expand Up @@ -55,8 +55,8 @@ export default {
mask () {
if (!this.$refs.input) return

const oldText = this.$refs.input.value || ''
const newText = this.maskText(this.lazyValue || '')
const oldText = this.$refs.input.value
const newText = this.maskText(this.lazyValue)
let position = 0
let selection = this.selection

Expand Down
1 change: 1 addition & 0 deletions src/util/mask.js
Expand Up @@ -90,6 +90,7 @@ const maskValidates = (mask, char) => {
* @return {String}
*/
export const maskText = (text, masked, dontFillMaskBlanks) => {
if (text == null) return ''
text = String(text)
if (!masked.length || !text.length) return text
if (!Array.isArray(masked)) masked = masked.split('')
Expand Down

0 comments on commit 95b7f83

Please sign in to comment.