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

With a checkbox to get the value is wrong #349

Open
xiyangjun opened this issue Dec 16, 2016 · 1 comment
Open

With a checkbox to get the value is wrong #349

xiyangjun opened this issue Dec 16, 2016 · 1 comment

Comments

@xiyangjun
Copy link

vue & vue-validator version

2.0.3, 3.0.0-alpha.1

Reproduction Link

<div id="vue-test">
    <validation name="validation">
        <form class="form-horizontal">
            <div class="form-group">
                <label class="col-sm-3 control-label">checkbox</label>
                <div class="col-sm-9">
                    <validity-group field="checkbox" :validators="{fn: true}">
                        <label class="checkbox-inline" v-for="(item, index) in list">
                            <input type="checkbox" name="checktest" v-model="checkedList" :value="item.value"  @change="handleValidate">{{item.text}}
                        </label>
                    </validity-group>
                </div>
            </div>
        </form>
    </validation>
</div>
new Vue({
    el: '#vue-test',
    data: {
        list: [{value: 1, text: 'test1'}, {value: 2, text: 'test2'}],
        checkedList: []
    },
    validators: {
        fn: function (val) {
            console.log(val);
        }
    },
    methods: {
        handleValidate: function(e) {
            var $validity = e.target.$validity
            $validity.validate();
        }
    }
});

Steps to reproduce

checked test1 and test2

What is Expected?

expect => log out [1, 2]

What is actually happening?

actually =》 log out ["1", "2"]

@xiyangjun
Copy link
Author

I think the wrong code here

MultiElement.prototype._getCheckedValue = function _getCheckedValue () {
  var value = [];
  this._eachItems(function (item) {
    if (!item.disabled && item.checked) {
      value.push(item.value);
    }
  });
  return value
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant