Search code examples
javascripthtmlvalidationvue.jsvee-validate

V-validate not working with interpolated attribute


When I use a static attribute, validation errors appear as expected:

<input type="number" name="phone" v-validate="'required|digits:10'">
<span>{{ errors.first(propertyName) }}</span>

But what if I don't want to hardcode the validation rules in the JavaScript? I would think this would work:

<input type="number" name="phone" :v-validate="phone.rules">
<span>{{ errors.first(propertyName) }}</span>

But no validation errors are appearing. Any ideas what I'm doing wrong?


Solution

  • I have created jsFiddle and everything seems to work fine. Feel free to check: https://jsfiddle.net/m67d8f4x/2032/

    <input type="email" name="email" placeholder="Email" v-validate="rules.rule" v-model="email">
    // js
      data() {
        return {
          rules: { rule: 'required' },
          email: ''
        }
      },