HelloWorld
HelloWorld

Reputation: 438

Zend setData method prevents Collection::setCount working

I have a Zend_Form with a Collection of Select elements. I want to increase the number of elements in that collection whilst also preserving any selection made previously (previous selections are stored in a POST request).

I use $form->setData($data); to save the values in the POST request to the Zend_Form.

I then use $form->get('countryTest')->setCount(9); to try and increase the number of Selection elements in the Collection. However, setCount() doesn't seem to change the count when used in combination with setData(). Any idea why? What should I do instead?

My Collection:

$this->add(array(
            'name' => 'countryTest',
            'type' => 'Collection',
            'options' => array(
                'label' => '',
                'count' => 3,
                'should_create_template' => true,
                'target_element' => array(
                    'type' => 'Select',
                    'options' => array(
                        'label' => 'Country',
                    ),
                ),
            ),
        ));

EDIT:

I've also tried constructing a new Zend_Form with a larger number of elements in the Collection and THEN using setData() but doing this seems to reduce the number of elements in the Collection to the number of elements in the data (probably as expected).

Upvotes: 0

Views: 86

Answers (1)

HelloWorld
HelloWorld

Reputation: 438

Found a solution:

Make the number of elements I want present in the array (in the form of keys) that I pass into setData().

Upvotes: 0

Related Questions