8000 v-model: checkbox respect number param in array mode · bencode/vue@56dd2cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 56dd2cf

Browse files
committed
v-model: checkbox respect number param in array mode
1 parent 22c8a49 commit 56dd2cf

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/directives/public/model/checkbox.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ module.exports = {
55
bind: function () {
66
var self = this
77
var el = this.el
8+
var number = this.param('number') != null
9+
10+
this.getValue = function () {
11+
return el.hasOwnProperty('_value')
12+
? el._value
13+
: number
14+
? _.toNumber(el.value)
15+
: el.value
16+
}
817

918
function getBooleanValue () {
1019
var val = el.checked
@@ -20,7 +29,7 @@ module.exports = {
2029
this.listener = function () {
2130
var model = self._watcher.value
2231
if (_.isArray(model)) {
23-
var val = getValue(el)
32+
var val = self.getValue()
2433
if (el.checked) {
2534
if (_.indexOf(model, val) < 0) {
2635
model.push(val)
@@ -42,7 +51,7 @@ module.exports = {
4251
update: function (value) {
4352
var el = this.el
4453
if (_.isArray(value)) {
45-
el.checked = _.indexOf(value, getValue(el)) > -1
54+
el.checked = _.indexOf(value, this.getValue()) > -1
4655
} else {
4756
if (el.hasOwnProperty('_trueValue')) {
4857
el.checked = _.looseEqual(value, el._trueValue)
@@ -52,9 +61,3 @@ module.exports = {
5261
}
5362
}
5463
}
55-
56-
function getValue (el) {
57-
return el.hasOwnProperty('_value')
58-
? el._value
59-
: el.value
60-
}

0 commit comments

Comments
 (0)
0