-
-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Labels
BugSomething isn't workingSomething isn't working
Description
Bug Report
| Q | A |
|---|---|
| Version(s) | 3.9.0 |
Summary
In laminas-form v3.9.0 some changes were made (#207) to ComposedObject. I believe this has caused Required(false) to now be ignored, meaning ComposedObjects are always checked, which breaks existing configuration.
Current behavior
If you annotate an element with
/**
* @Form\Required(false)
* @Form\ComposedObject("Application\Model\SubForm")
*/
private ?SubForm $subForm;and then plug empty values into a form using laminas-form's ->setData([]), then:
->isValid()returnsfalse->getMessages()returns['subForm' => ['name' => 'Value is required and can't be empty']]
How to reproduce
Full working example below. Uncomment the 'name' => 'test', for the form to be valid, and run in 3.8.0 for it to work fine.
<?php
declare(strict_types=1);
use Laminas\Form\Annotation\AnnotationBuilder;
use Laminas\Form\Annotation as Form;
require __DIR__ . '/vendor/autoload.php';
class SubForm
{
/**
* @Form\Required(true)
*/
private string $name;
}
class MyForm
{
/**
* @Form\Required(false)
* @Form\ComposedObject("SubForm")
*/
private SubForm $subForm;
}
$builder = new AnnotationBuilder();
$form = $builder->createForm(MyForm::class);
$form->setData([
'subForm' => [
// 'name' => 'test',
],
]);
var_dump($form->isValid());
var_dump($form->getMessages());Expected behavior
I expected the behavior in 3.8.0, that the entire object can be omitted if @Form\Required(false) is present.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugSomething isn't workingSomething isn't working