SelectBox value is not sent in form ajax post

Notice: This thread is very old.

6 years ago

Member | 58

I found strange behaviour in ajax form call.
I have this structure: RootComponent → Component → Form
Im creating Form by Multiplier.
When Form is submited normaly, everything is OK.
When Form is ajax submited, value from SelectBox is NULL, but value from hidden input is ok.
Im not sure if Component hierarchy is important, but for sure i mention it.
Im using Nette 2.1.5, PHP 5.4.12

Here is my Form factory in Component:


protected function createComponentProductMoveForm() {
        $categoryValues = array(1 => 'Cat 1', 2 => 'Cat 2');
        $defaultCategoryId = 1;

        return new Multiplier( function ($itemId) use ($categoryValues, $defaultCategoryId) {
            $form = new Form;

            $form->addSelect('categoryId', 'Category', $categoryValues)
            $form->addSubmit('send', 'Move');

            $form->onSuccess[] = $this->productMoveFormSuccess;

            return $form;
        } );

	public function productMoveError(Form $form){
		// In Ajax call get these, everything is OK if post without ajax
        dump($form->getvalues()); // categoryId => NULL,  productId sent properly
        dump($form->getHttpData()); // categoryId => "1",   productId => sent properly
        dump($form->errors); // "Please select a valid option."

If form is posted by ajax, it ends up with error Please select a valid option. because sent value for SelectBox categoryId is NULL.
When I take form values by $form->getHttpData() there is categoryId = 1, which is correct.

Please, can anybody help me with this?
Thanks for reaply.

Last edited by ajda2 (2014-09-12 10:25)