This repository was archived by the owner on Dec 12, 2021. It is now read-only.
Closed
Conversation
Owner
|
This could be solved today like this: var constraints = {
foo: {
presence: function(value, attributes, attribute, options, constraints) {
return options.method !== 'PUT' ? {} : null
}
}
};
validate({}, constraints, {method: 'POST'});
// {"foo": ["Foo can't be blank"]}
validate({}, constraints, {method: 'PUT'});
// undefinedI understand this is not as nice as having a dedicated option for it but I don't want to add validator specific options unless there is a very good reason. I'm in the processing of implementing a change that will pass the global options to a custom validator which means you could do something like this: var presence = validate.validators.presence;
validate.validators.presence = function(value, options, key, attributes, globalOptions) {
return globalOptions.method === 'PUT' ? null : presence.call(presence, arguments);
};It should be ready within the hour. |
ansman
added a commit
that referenced
this pull request
Jul 9, 2015
The is to help the issue raised in #63
Author
|
This seems to be a more flexible alternative, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
This is a PR to add a
skipPresenceoptions tovalidate.This is useful to validate data on update.
For example, this would allow to write something like this.
Thanks.