kazupon / vue-validator

:white_check_mark: Validator component for Vue.js
MIT License
2.19k stars 431 forks source link

dynamically added fields are not detected by validator #296

Closed uptownhr closed 7 years ago

uptownhr commented 8 years ago

Hi,

I have a form with an input field that can be added on dynamically. For example, a click to add another input field. The first input field displayed is properly detected by the Validator but additional fields added in by the click even does not.

I have an array of fields where it is looped to create the input fields and the click event will cause an additional input field to be displayed.

When I output, {{$validator | json}} i can see the initial field but not the subsequent fields.

{
  "0": {
    "required": false,
    "modified": false,
    "pristine": true,
    "dirty": false,
    "untouched": true,
    "touched": false,
    "invalid": false,
    "valid": true
  },
  "valid": true,
  "invalid": false,
  "touched": false,
  "untouched": true,
  "modified": false,
  "dirty": false,
  "pristine": true
}

I'm currently using the :field attribute and using the index of the array as the field value. No matter how many I add, validator will only show the 0 index.

kazupon commented 8 years ago

Thank you for your feedback. Can you share the reproduction codes with jsfiddle (or codepen ... etc) please?

uptownhr commented 7 years ago

i will try and get one up this week.

kazupon commented 7 years ago

Close (inactivity)

SteveEdson commented 7 years ago

Also getting the same issue, replicated here:

https://jsbin.com/fofeborivu/edit?html,output

The dynamic field gets added to the last <validator> component on the page. So if you swap the order, the new field is added to the correct location. Similarly, if there is only one section on the page, it is added in the correct place.