Fixed #45: custom messages for custom validators#49
Open
mattiloh wants to merge 3 commits intotgriesser:masterfrom
Open
Fixed #45: custom messages for custom validators#49mattiloh wants to merge 3 commits intotgriesser:masterfrom
mattiloh wants to merge 3 commits intotgriesser:masterfrom
Conversation
I added a test for the 'allow the use of custom messages on failed validation', too. Unfortunately the test-setup seems not to work well with the promise-based interface of Checkit. Even failing tests are counted as passed and you only see the errors by scanning the test-list for thrown errors. I added a `done`-callback in a final `then(done, done)` to the Checkit-Promise of my test to make it work. All other tests should be updated, too. But I'll open an issue for that. There seemed to be some un-built changes of former commits. So lines 718 + 897 of `dist/checkit.js` are unrelated to this fix and contain new messages for the field-type *integer*.
Collaborator
There was a problem hiding this comment.
It seems strange that this modifies err. Is there another way?
Author
There was a problem hiding this comment.
Yes, you're right. I tried another way like this:
var errorMessage = validation.message || err.message;
...
fieldError = errors[key] = new FieldError(errorMessage)But unfortunately that only works for one validation-rule per field, as it will be only applied if fieldError is still undefined. If there are several errors for one field, the error-objects will just be pushed to the array fieldError.errors (in line 226).
Author
There was a problem hiding this comment.
I just refined the tests to check for validation-fields with one rule and with several rules. If I try the version without modifying err, it's not passing.
Author
|
Hi Rhys! Are there any suggestions on this? |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I added a test for the 'allow the use of custom messages on failed validation', too.
Unfortunately the test-setup seems not to work well with the promise-based interface of Checkit. Even failing tests are counted as passed and you only see the errors by scanning the test-list for thrown errors. I added a
done-callback in a finalthen(done, done)to the Checkit-Promise of my test to make it work. All other tests should be updated, too. But I'll open an issue for that.There seemed to be some un-built changes of former commits. So lines 718 + 897 of
dist/checkit.jsare unrelated to this fix and contain new messages for the field-type integer.I also added webpack to
package.jsonand changed the npm-scriptsbuildandtestto use local versions of mocha and webpack.