nhayder
127
2
Vue

how to clear validation span element on keydown

Posted 8 months ago by nhayder

i'm submitting a form with vue js,

            <div class="flex flex-wrap -mx-3 mb-3">
                <div class="w-full px-3 mb-6 md:mb-0">
                  <label class="block uppercase" >
                    @lang('translation.name')
                  </label>
                  <input class="w-full " type="text" name="name" v-model="name" >

                  <span v-if="errors.name" class="text-red text-xs">@{{errors.name[0]}}</span> // validation text

                </div>
            </div>

in app.js


// this is the errors object  errors      :               []

        addNewPage : function(){ 
            axios.post('/api/newpage', {

                // data to send
                name        : this.name,
                direction   : this.direction,
                language_id : this.language_id,
            })

            // success
            .then( response => alert('Success'))

            // errors
            .catch( error => {

                if (error.response.status == 422) {

                  this.errors = error.response.data.errors

                }

            })

            event.target.reset();

        },

if the form has erros laravel will show errors in the span element above, So my question how to clear the validation errors on @keydown for every input

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.