Reputation: 8075
I'm having a trouble getting a checkbox to pass 'isValid' from a form built using Zend Annotation builder with a Doctrine entity.
Even when I don't use a Required annotation and remove the validation, it still reports 'missing' on my checkbox "message": "Required fields are missing or invalid: Content"
Annotation in entity:
/**
* @var boolean $Content
*
* @ORM\Column(name="Content", type="boolean", nullable=false)
* @Annotation\Attributes({"type":"checkbox"})
* @Annotation\Options({"label":"Value:"})
* @Annotation\Filter({"name":"Boolean"})
* @Annotation\Validator({"name":"NotEmpty"})
*/
Content element in form:
Zend\Form\Element\Checkbox::__set_state(array(
'attributes' =>
array (
'type' => 'checkbox',
'name' => 'Content',
),
'validator' => NULL,
'useHiddenElement' => true,
'uncheckedValue' => '0',
'checkedValue' => '1',
'label' => 'Value:',
'labelAttributes' =>
array (
),
'labelOptions' =>
array (
),
'messages' =>
array (
),
'options' =>
array (
'label' => 'Value:',
),
'value' => '0',
));
Any help?
Upvotes: 1
Views: 575
Reputation: 1890
You get the error because of the '0'. Zend thinks that you a passing a false value and the NotEmpty validators throws an error.
form->getInputFilter()->get('Content')->setContinueIfEmpty(true)
should solve the problem.
Edit: check this articles as well. http://akrabat.com/setting-up-required-fields-that-can-be-empty-with-zendinputfilter/
Upvotes: 2