`custom()` validation not working
See original GitHub issueHere’s an abstract of the code I’m working with:
import { check } from 'express-validator/check';
router.post(
'/myendpoint',
[
check('myparameter', 'This should be hardcoded to fail')
.custom((value, { req }) => {
console.log(value);
return false;
})
],
myEndpointHandler
);
I’m using a custom check to validate a query parameter, and after trying everything to get it to work, I distilled it down to something that looks just like the code in the documentation, and it still won’t work. It’s not asynchronous, it’s just a boolean check. I took out my boolean check and hardcoded in false
, but it still doesn’t work. I’m running it with v4.3.0. I added the console.log(value)
and it’s printing the correct value that gets passed in. Is there something I’m missing, or is custom()
not fully working, or is the documentation out of date?
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Custom Validator not firing - Stack Overflow
CustomValidators don't fire if other Validators in your ASPx are not validating. You may need to force a Page.Validate("something") ...
Read more >Server Side CustomValidator not working - MSDN - Microsoft
The key here is that you should always setup server side validation. Its already been mentioned. Make sure Page.Validate() runs (which happens ...
Read more >Custom validation not firing :( | WordPress.org
Hello, I'm trying to add a custom validation to a text field to both Login and Registration forms, but I can't get it...
Read more >Form validation is not working in my custom form in Magento 2
this is my phtml code. Here when i am submitting the form with empty fields, form validation is not triggering, it is submitting...
Read more >custom validation not working - Our Umbraco
$scope.validationTest = null; $scope.validateMandatory = function () { return { isValid: false, errorMsg: "Value cannot be empty", errorKey: " ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey guys, so I checked both of your codes and they both work.
@valeco I added a
console.log(req.flash())
to your error handler and it prints all messages, includingWrong!
😉@KrashLeviathan I replaced that route with the following:
You were probably missing the call to
validationResult
.Will close the issue for now. Feel free to continue the discussion.
Sorry @valeco but I still can’t reproduce. I commented out the other validators and sanitisers and it still works. I must also comment that I had to remove the mongoose connection.
Can you please create a minimal example that reproduces your issue?