Giter Club home page Giter Club logo

Comments (3)

weierophinney avatar weierophinney commented on July 17, 2024

As noted on #12:

Currently, allow_empty and continue_if_empty are false by default, and required 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.

larsnystrom avatar larsnystrom commented on July 17, 2024

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.

marcuswinkler avatar marcuswinkler commented on July 17, 2024

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 in BaseInputFilter
  • set continue_if_empty to true, to actually hit the validators in Input
  • append a NotEmpty validator, to reject missing or empty values

from zend-inputfilter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.