Skip to content
This repository has been archived by the owner on Dec 25, 2017. It is now read-only.

Commit

Permalink
fix(model): fix field empty bug 🐛
Browse files Browse the repository at this point in the history
Closes #195
  • Loading branch information
kazupon committed Apr 20, 2016
1 parent 675a238 commit 360a209
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/validations/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class BaseValidation {
const scope = this._getScope()
const model = this._model
if (model) {
el.value = this._evalModel(model, this._filters) || ''
el.value = this._evalModel(model, this._filters)
this._unwatch = scope.$watch(model, (val, old) => {
if (val !== old) {
if (this.guardValidate(el, 'input')) {
Expand Down Expand Up @@ -260,11 +260,13 @@ export default class BaseValidation {
_evalModel (model, filters) {
const scope = this._getScope()

let val = null
if (filters) {
let val = scope.$get(model)
val = scope.$get(model)
return filters ? this._applyFilters(val, null, filters) : val
} else {
return scope.$get(model)
val = scope.$get(model)
return val === undefined || val === null ? '' : val
}
}

Expand Down
1 change: 1 addition & 0 deletions test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ require('./reset')
require('./validate')
require('./initial')
require('./async')
require('./issues')
33 changes: 33 additions & 0 deletions test/specs/issues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'power-assert'
import Vue from 'vue'


describe('github issues', () => {
let el, vm

beforeEach(() => {
el = document.createElement('div')
})


describe('#195', () => {
beforeEach((done) => {
el.innerHTML = '<validator name="validator1">'
+ '<form novalidate>'
+ '<input type="text" v-model="value" number>'
+ '<input type="text" v-model="value" number v-validate:value="[\'required\']">'
+ '</form>'
+ '</validator>'
vm = new Vue({ el: el, data: { value: 0 } })
vm.$nextTick(done)
})

it('should be validated', (done) => {
let field1 = el.getElementsByTagName('input')[0]
let field2 = el.getElementsByTagName('input')[1]
assert(field1.value === '0')
assert(field2.value === '0')
done()
})
})
})

0 comments on commit 360a209

Please sign in to comment.