mikeerickson / validatorjs

A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
https://www.npmjs.com/package/validatorjs
MIT License
1.77k stars 280 forks source link

"sometimes" rule #69

Closed nikinicky closed 8 years ago

nikinicky commented 8 years ago

In some situations, I may wish to run validation checks against a field only if that field is present in the input array. We know that Laravel validation framework has this feature. Does validatorjs have this feature ?

iamdtang commented 8 years ago

No, validatorjs does not have this rule. Want to add it? =)

yangmillstheory commented 8 years ago

Hi, nice library!

Is someone working on this issue?

I'm not familiar with Laravel; could @nickiesiva or @skaterdav85 post a code snippet that illustrates the desired behavior?

iamdtang commented 8 years ago

In some situations, you may wish to run validation checks against a field only if that field is present in the input array. To quickly accomplish this, add the sometimes rule to your rule list:

https://laravel.com/docs/5.2/validation#conditionally-adding-rules

@yangmillstheory If you'd like to work on it, go for it :)

yangmillstheory commented 8 years ago

OK, I've cloned the repo, built and ran the tests.

What do you think about a section in the REAMDE for guidelines for contributing? I also noticed that you hadn't listed gulp-cli as a devDependency but I don't have it (and don't want it) installed globally. We could lock down a version that works specifically with your project.

iamdtang commented 8 years ago

There is another file for contributing, but it could be improved. https://github.com/skaterdav85/validatorjs/blob/master/CONTRIBUTE.md

Do you mean grunt instead of gulp? If you have a local version of grunt, is there a way to run it that way? If so, sure you can change that. The scripts section in the package.json will need to be updated.

yangmillstheory commented 8 years ago

Yes, I meant Grunt, thanks. It would install to node_modules/.bin/grunt, and developers would be running that specific version instead of what's in their global node_modules folder, somewhere in /usr/local/ in a *nix environment.

If they don't have it installed globally (like me), they get something like

validatorjs (master u= ?!) $ grunt
-bash: grunt: command not found

I've been using this shorthand since I like not prefixing commands with node_modules/.bin every time I run a project-specific binary.

iamdtang commented 8 years ago

cool, ya I like that better too. If you want to make that update, go for it. :)

Patrik-Lundqvist commented 8 years ago

Useful feature, nice work. I hope this will be included in a new release soon!

iamdtang commented 8 years ago

@Patrik-Lundqvist Just released the latest as 3.7.0