[Vuejs]-How to validate a dynamically added input in a form?

0👍

If you use laravel’s request class, you can validate all fields there to see if any are empty.
This is by far the easiest and most robust way to do this.

This will validate your request before it gets to the controller and will allow you to return custom errors.

You’ll probably want to store all dynamically added fields in a nested array so you can check that individually.

In the rules section you’d write something like this:

'dynamic_fields.*' => ['required']

Hope this helps.

0👍

i will give you and idea of what i would do

methods: {
validate(){
 this.questionOptions.forEach(function(item, key) {      
 if(item.multipleChoice){
   if(item.option===''){
         alert('this question can not be null ' + item.question  )
         return 
      }
   }  
  }
 }

Leave a comment