Dynamic collection validation
i have a variable items(array of objects) with 3 attributes for every item (value, other and otherKey), for every item, the value field is required, the other field is required only if value field value is equal to otherKey field.
Look the example on jsfiddle
Since you’re iterating over more complex structures, please create a child component that will handle those validations inside. I’d avoid using $each if possible.
HI i am also in same kind of situation. here is my validation object
validations: {
filterRows: {
$each: {
fieldName: {
required
},
operator: {
required
},
value: {
firstValue: {
required
},
secondValue: {
required // should only require if operator is equal to range.
}
}
}
}
}
i am wondering if i can use requiredIf. I dont even know how i can use requiredIf in this case. I dont see any example of requiredIf where i can use the value of other property to see if requiredIf true or false.
@sarkariajatt technically, if you pass a function to the requiredIf validator, it will give you the current value as first param, and its top level siblings as a second param. In the this context you will find your whole Vue component instance. However, this is inside an each validator, so you wont really be able to reach easily into the current looped index so to speak. As @shentao said. moving the validation into your sub component and somehow collecting the results may be your best bet for now. It is hacky. but to be honest, this will be also.
Same situation here. I am rendering input fields into table, with nested JSON object data. The validation required to access variables from loop (under $iter), but just can't figure out a solution. I guess the sub-component workaround would only works for two level deep of data structure? What if it has 3 or more? Any help would be appreciated.
+1