Comments (10)
We had the same issue that 'Value is required' message can not be localized to Chinese as it is hardcoded in the framework code. The custom-message NotEmpty validator cannot override this error message like this case. Please help to make the hardcoded message localizable.
from zend-inputfilter.
@tflin please open a new issue
from zend-inputfilter.
@larsnystrom I don't understand what do you refer about override required attribute. I can say the second commit of #25 will make the messages consistent using the message of test 2
from zend-inputfilter.
@Maks3w I think he speaks about this
zend-inputfilter/src/BaseInputFilter.php
Line 270 in bded51b
from zend-inputfilter.
I've created a repo to make it easier to reproduce the bug.
git clone https://github.com/larsnystrom/zend-inputfilter-ticket14
composer install
php test.php
I haven't tested PR #25, I'll do that if I ever get the time.
from zend-inputfilter.
@larsnystrom We've never had setting a NotEmpty validator toggle the required flag; the only correlation between the two is that in past versions, setting the required flag to true would implicitly add a NotEmpty validator. We've changed that logic recently, however (we now check for absence of a value when the required flag is true, and invalidate earlier when that condition arises). Is it possible that's the issue you're seeing?
from zend-inputfilter.
@weierophinney If you look at the MyFilter::init()
method in the test code above, you'll see that I've set required
to true and also added a NotEmpty validator to both input specifications in the InputFilter. Then, if a field is empty, the NotEmpty validator should run and fail, right? As you yourself wrote in #11
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.
That is exactly what I've done.
Now, if you look at test case 1, you'll see that this works when both fields are empty! Fantastic.
Moving on to test case 2, where only one of the fields are empty. I'd expect the corresponding NotEmpty validator to run and fail, right? That's what happened in the first test case. But (here comes the bug) the NotEmpty validator doesn't run and instead the required
attribute and its associated logic takes precedence.
The behaviour is different when (1) all fields are empty and (2) only one field is empty. That's the bug.
from zend-inputfilter.
Fields on test 1 are not empty. Are not set. Value is unknown so can't be determined if value is empty or not.
from zend-inputfilter.
Please test against current master
from zend-inputfilter.
The current master solves the inconsistence, but makes it completely impossible to customize the "Value is required" message when there isn't a value. But that's discussed in other issues (#11 and #28), so I'll close this issue now.
Another issue is that the fallback value isn't validated. Personally I'd prefer if it was validated/filtered just like any other value. But that's outside the scope of this issue.
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.