kazupon / vue-validator

:white_check_mark: Validator component for Vue.js
MIT License
2.19k stars 431 forks source link

$validation.shortTitle.errors is undefined if I don't set a message for each rule #245

Closed felixpy closed 8 years ago

felixpy commented 8 years ago

Here is the html:

<div class="form-group control-group">
    <label class="col-xs-1 control-label" for="shortTitle">shortTitle:</label>
    <div class="col-xs-5 controls">
        <input v-model="param.shortTitle" v-validate:short-title="{maxlength:12}" type="text" class="form-control" name="shortTitle">
        <div v-if="$validation.shortTitle.maxlength"><span class="validator-error">Short title is too long</span></div>
    </div>
</div>

Only when I changed the v-validate derective to v-validate:short-title="{maxlength:{rule:12,message:'Too long'}}" can I get the "errors" array. So how can I fix this? Thanks.

kazupon commented 8 years ago

Thank you for your reporting! I tried to reproduce this issue, but I could not. Can you provide the minimum reproduction example code with jsfiddle(or jsbin, codepen...etc) please?

felixpy commented 8 years ago

Sorry for the late response. Here is the example: jsfiddle I think "errors" array should list all errors even without specified message. BTW, is there a way to add default message for those rules already in vue-validator(required, maxlength, etc.)?

kazupon commented 8 years ago

Sorry for late response. I checked the your jsfiddle code. This is the expectable behavior of vue-validator.

.>BTW, is there a way to add default message for those rules already in vue-validator(required, maxlength, etc.)?

You can the set the below.

Vue.validator('required', {
  message: function (field) { // string or function
     return 'required "' + field + '"' 
  },
  check: Vue.validator('required')
})
felixpy commented 8 years ago

Thx, I'll try it.