Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Form via AnnotationBuilder in extended form doesn't use validators and filters #4220

Open
jirinapravnik opened this Issue · 2 comments

2 participants

@jirinapravnik

I create form via AnnotationBuilder and I want to add new elements to it. I can use it in controller and add new elements there. But it's not nice approach to add new elements in the controller and it's better add them in the extended form. Inputs are added sucessfuly, but filters and validators don't wok.

Entity:

use Zend\Form\Annotation as Form;
/** 
 * @Form\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")
 * 
 */
class Category {

    /**
     * @Form\Type("Zend\Form\Element\Hidden");
     */
    protected $id;

    /**
     * @Form\Required(true)
     * @Form\Filter({"name" : "StringTrim"})
     */
    protected $name;   
}

Form:

class Edit extends Form {

    public function __construct() {
        parent::__construct('categoryMain');


        $builder = new AnnotationBuilder();
        $form = $builder->createForm(new Category());
        $this->add($form);

        $this->add(
                array(
                    'type' => 'submit',
                    'name' => 'save'
                )
        );
  }
}

In controller:

$form = new Edit();
$form->isValid();

Return always true (even if the name element is empty).

@samsonasik

you should use * @Annotation\Filter({"name":"StringTrim"})

@jirinapravnik

It is not that problem, I have Form\Annotation namespace as: use Zend\Form\Annotation as Form; . I updated issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.