-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for rules/related validation with Array path. (DVR) #328
Comments
Right now using the array notation in the rules is not supported, you should specify the index of the array to validate inside the rule, so I suggest to dynamically create the rules: const makeMemberIdRules = (id) =>
'boolean|required_without:members[' + id + '].age';
form.$('members')
.each((field) => (field.name === 'id') &&
field.set('rules', makeMemberIdRules(field.container().name))); I updated your demo: https://www.webpackbin.com/bins/-Kv7y24BahF4zIdxa1nv I will implement this feature in the future versions. |
Related to #249 |
Thanks a lot for the swift response. You saved me a lot of grief 👍 |
It's been one year , any progress on this issue? ta |
@foxhound87 the demo link is not available anymore. Where should I add the code you pasted for array validation to work? |
I'm not sure if I'm doing something wrong, but I'm trying to make validation work with an array of objects where 2 properties are related to each other, e.g. at least one needs to be present.
In the demo below: members[].id should be required unless the members[].age is present.
At least that's the goal, am I doing something wrong or is there a bug in the lib?
Link to the demo
Lib versions:
mobx: 3.3.0
mobx-react-form: 1.32.2
validatorjs: 3.13.5
Output
Code for the demo
Edit: code format fix
The text was updated successfully, but these errors were encountered: