Comments (3)
As noted on #12:
Currently,
allow_empty
andcontinue_if_empty
are false by default, andrequired
is true. This combination does injects a NotEmpty validator to the top of the ValidatorChain setup to break on error (i.e., if it fails, no more validators are executed); the validation chain is then executed, and, if the value is empty, the input is marked as invalid.The solution to #11 is to keep the input as required, but to inject your own NotEmpty validator at the top of the chain yourself; Input will detect that it's present, and not inject its own NotEmpty validator.
So, the solution is:
- Keep the input
required
- Inject your own
NotEmpty
validator with the custom message as the first validator in the chain.
from zend-inputfilter.
Even if that solved my problem (which it doesn't, but I'll open a separate ticket for that see #14 ) I still think it'd be a good idea to be able to override the 'Value is required' message. As it stands, it is impossible to customize the message which makes it very hard to localize or improve UX by providing a more specialized description of what went wrong.
from zend-inputfilter.
In the case of a required
value which is missing from the input array, BaseInputFilter
will never ask the Input
instance to validate but will reject the element itself, setting the hard-coded error message.
So adding your own error message to the input can't work.
My workaround is this:
- set
required
to false, to bypass the check inBaseInputFilter
- set
continue_if_empty
to true, to actually hit the validators inInput
- append a
NotEmpty
validator, to reject missing or empty values
from zend-inputfilter.
Related Issues (20)
- Class Zend\ServiceManager\AbstractPluginManager not found HOT 5
- Avoiding the default NotEmpty::IS_EMPTY validation message. HOT 3
- CollectionInputFilter throws exception on scalar input HOT 3
- ConfigProvider - registration of InputFilterAbstractServiceFactory HOT 1
- Value is required message for optional field HOT 8
- [php 7.2] incompatible prototype HOT 2
- InputFilter::getValues() does not throw like it should HOT 2
- Intended behaviour on nested input filters and empty POST data? HOT 2
- FileInput not compatible with PSR (and Dictatoros) UploadedFile HOT 3
- How use Callback validator when field is conditionally required? HOT 3
- Duplicate error messages for collection input field items HOT 14
- Version 2.8.5 broke backward compatibility for apigility HOT 4
- Null value for inputfilter causes exception HOT 28
- Add support for required flag to input filters HOT 2
- collectionRawValues not populated in setData of CollectionInputFilter HOT 15
- MVC InputFilterPluginManager missing InputFilterAbstractFactory config HOT 15
- Input filter specification and merging HOT 1
- Exception when supplying non-array data to an ArrayInput HOT 2
- Empty validation message for file input when sent array for file input HOT 3
- Fatal error: Class 'Zend\ServiceManager\AbstractPluginManager' not found in D:\XAMPP\htdocs\sn\zend-mail\vendor\zendframework\zend-mail\src\Protocol\SmtpPluginManager.php on line 20 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zend-inputfilter.