Skip to content
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

Feature Request: validatePresenceOn #189

Closed
jhitchins88 opened this issue Jan 17, 2019 · 6 comments
Closed

Feature Request: validatePresenceOn #189

jhitchins88 opened this issue Jan 17, 2019 · 6 comments

Comments

@jhitchins88
Copy link
Contributor

Suggested Addition

The validatePresenceOn validator: validate presence if other field(s) are also there.

How it works

export default {
  lastName: validatePresenceOn('firstName'),
  password: validatePresenceOn([ 'email', 'ssn', 'address', ])
}

Alternatively, it could be an option for the validatePresence validator:

export default {
  lastName: validatePresence({ on: 'firstName' }),
  password: validatePresence({ on: [ 'email', 'ssn', 'address', ] })
}

This is something I wrote as a custom validator, so if it's something you would like, I can put up a PR.

@snewcomer
Copy link
Collaborator

@jhitchins88 This seems like a phenomenal idea. Lmk if you have time for a PR!

@nickschot
Copy link
Contributor

@jhitchins88 how did you write this validator? Don't the validators only receive the key and the value of the property that is validated?

I'm very interested in this (and a similar validator where at least one of several fields must be present/have a specific format).

@jhitchins88
Copy link
Contributor Author

@snewcomer I should be able to do it. I'll work it up into a PR soon.

@nickschot I used the changes and content (4th and 5th parameters) passed into the validator function. Those let you look at the whole changeset.

@musaffa
Copy link

musaffa commented Feb 26, 2019

@nickschot a similar validator where at least one of several fields must be present/have a specific format

@jhitchins88 Can you add this feature as well?

@jhitchins88
Copy link
Contributor Author

@musaffa

I'd need a little more description of "have a specific format", but I'd be down if we know what that looks like. If it gets too much more complicated, we should probably break this functionality into its own validator, or have some way to do conditionals in the validations file, like #116 suggests. This on option is basically just a fancy, specific conditional, that could be replaced with a general conditional for any validator in the future.

@musaffa
Copy link

musaffa commented Feb 28, 2019

@nickschot Can you please clarify this format validation of one field in another field?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants