Vee-validate: Custom Component with vee-validate

Created on 26 Dec 2017  路  2Comments  路  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.3.3
  • Vee-Validate: 2.0.0-rc.25

Description:

I have a custom component. It is a input with a characteres counter, and i tried to put vee-validate inside this input. I want to show errors when Form is Submited. I followed every step in vee-validate document, but it did not work. My form submits itself ignoring any input's error.

Steps To Reproduce:

Create a custom component using vee-validate

CODE:

Parent.vue

   <vue-input maxlength="20" minlength="3" placeholder="works"
    validate="required|numeric" v-model="dataItem.teste" name="teste"></vue-input>

Component.js

Vue.component('vue-input', {
    props: ['maxlength', 'minlength', 'placeholder', 'validate', 'value', 'name'],
    template: `<div>
              <div class="input-group">
                <input type="text" :name="name" :value="value" 
                @input="$emit('input', $event.target.value); 
                counter = $event.target.value.length" 
                :maxlength="maxlength" :placeholder="placeholder" 
                v-validate="validate" 
                :class="{'is-danger': errors.has(name), 'form-control' : true}">

                Erros: {{errors}}
                <span class="input-group-addon">
                    {{ maxlength - counter }}
                </span>

                <span v-show="errors.has(name)" class="text-danger m-t-xs">
                    {{ errors.first(name) }}
                </span>
             </div>
             </div>`,
             data: () => ({
                 counter: 0
             })
});

Most helpful comment

Because your form doesn't know about the errors inside your component, you can either store each field valid status with a prop.sync binding, or inject the parent validator into its children instead.

http://vee-validate.logaretm.com/advanced#injection

Here is the updated example:

https://jsfiddle.net/9o5wsfm1/

All 2 comments

Because your form doesn't know about the errors inside your component, you can either store each field valid status with a prop.sync binding, or inject the parent validator into its children instead.

http://vee-validate.logaretm.com/advanced#injection

Here is the updated example:

https://jsfiddle.net/9o5wsfm1/

Thankss!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

triffer picture triffer  路  3Comments

HunterJS-bit picture HunterJS-bit  路  3Comments

schel4ok picture schel4ok  路  3Comments

MeltedFreddo picture MeltedFreddo  路  3Comments

MaxMilton picture MaxMilton  路  3Comments