Skip to content

required input - unable to set custom isEmpty message #2

@j-schumann

Description

@j-schumann

When using an inputSpecification using required=true we could use a notEmpty validator in the chain to set our custom error message when the input was not set:

return [
            'name'     => $this->getName(),
            'required' => true,
            'filters'  => [
                ['name' => 'Zend\Filter\StringTrim'],
            ],
            'validators' => [
                [
                    'name'                   => 'Zend\Validator\NotEmpty',
                    'break_chain_on_failure' => true,
                    'options'                => [
                        'messages' => [
                            \Zend\Validator\NotEmpty::IS_EMPTY => 'custom message',
                        ],
                    ],
                ],
                // further validators
            ],
        ];

InputFilter would then use this validator to get the error message. But now Zend\InputFilter\Input uses prepareRequiredValidationFailureMessage() the default NotEmpty::IS_EMPTY message without any option to customize this.
There is a pull request open to fix this zendframework/zend-inputfilter#73 but it is not merged yet while other solutions are discussed...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions