Zend Framework 2 Form Collection Validator

202 views Asked by At

Is it possible to validate form collection to make sure it contains at least N elements?

To add a collection to the form I use the following notation:

    $this->add(array(
         'type' => 'Zend\Form\Element\Collection',
         'name' => 'categories',
         'options' => array(
             'label' => 'Please choose categories for this product',
             'count' => 2,
             'should_create_template' => true,
             'allow_add' => true,
             'allow_remove' => true,
             'target_element' => array(
                 'type' => 'Application\Form\CategoryFieldset',
             ),
         ),
     ));

We can see that minimum number of elements is set to 2, but it still allows to save the form with only 1 element.

0

There are 0 answers