-
Notifications
You must be signed in to change notification settings - Fork 49
Missing required failure message for CollectionInputFilter #94
Comments
Is this fixed? Using the latest version, and it seems indeed that the collection input filter does not have some sort of default message when required is true and an empty array is given. Need to extend the input filter for now. |
Issue is still exists. @weierophinney can you confirm this? |
Any updates on this? Problem still exists. |
Please provide us with a minimal coffee sample that demonstrates the issue; right now, we'd be doing guess work. |
Example Input Filter$factory = new \Zend\InputFilter\Factory();
$inputFilter = $factory->createInputFilter(
[
'collection-element' => [
'type' => \Zend\InputFilter\CollectionInputFilter::class,
'required' => true,
'input_filter' => [
'type' => [
'required' => true,
'validators' => [
[
'name' => \Zend\Validator\Between::class,
'options' => [
'min' => 50,
'max' => 100,
],
],
],
],
'price' => [
'required' => true,
'validators' => [
[
'name' => \Zend\Validator\Between::class,
'options' => [
'min' => 50,
'max' => 100,
],
],
],
],
],
],
]
); First Try, when you have a problem with empty error message$inputFilter->setData([]);
var_dump($inputFilter->isValid());
var_dump($inputFilter->getMessages()); Second Try with Valid error messages if provided some data$inputFilter->setData([
'collection-element' => [
0 => [
],
],
]);
var_dump($inputFilter->isValid());
var_dump($inputFilter->getMessages()); |
Output is: First try
Second try
|
No error message is generated. Compare the zend-inputfilter/src/Input.php Lines 410 to 415 in a2962cf
zend-inputfilter/src/CollectionInputFilter.php Lines 171 to 213 in a2962cf
|
Do you have any updates related this issue? |
@developer-devPHP No, no updates at this time. We actually need to address this by getting some feedback first. InputFilters do not have a concept of required/optional by default. We tacked it on to the Normally, if data is present, 0 => [
'foo' => [ /* array of messages */]
],
1 => [
'bar' => [ /* array of mesages */ ]
],
/* etc. */ The problem area is that the each element of the above array is expected to be an array of key/messages pairs. How, exactly, do we represent a message indicating that a data set was empty in a way that is either consistent in structure, or easily differentiated from the existing structure? Some thoughts off the top of my head:
We need to choose one, but I need input from users as to which one to choose. Additionally, we need:
If anybody would like to tackle this, I'd appreciate the help. |
I have a solution for this. Please have a look into pull request #170 |
CollectionInputFilter fails without error message when is required but data is empty or not set.
The text was updated successfully, but these errors were encountered: