Validate child input components on submit with Vee-Validate

前端 未结 6 507
-上瘾入骨i
-上瘾入骨i 2021-01-17 17:36

I\'m currently trying to create a Registration form with multiple \"Input Field\" components which all require validating once Submit has been pressed. They all currently va

6条回答
  •  心在旅途
    2021-01-17 17:54

    I'm not sure I understand you correctly. But to make the call globally, you will have to emit an event on clicking the button and instruct each template to act upon that event. The action for each template should be to 'this.$validator.validateAll()', because 'this' will refer to that specific template.

    You can do that by creating a named instance ('bus'). Create that before creating the instance.

    var bus = new Vue({});
    

    Use that to emit from the template:

    bus.$emit('validate_all');
    

    and to catch in a template:

    created: function() {
       var vm = this;
       bus.$on('validate_all', function() {
          vm.$validator.validateAll()
       });
    }
    

    Now all fields should have been validated and all error messages should show. Good Luck!

提交回复
热议问题