how can i made textfields with the same name into form classes

15 days ago

Member | 100

hi there im trying to build a forms with same name textfields as array ex: mytextfield[], here is what is talking about

                    '{"1":3.5}'=>"Hielo grande",
                    '{"2":2.5}'=>"Hielo pequeño",
                $this->form->addCheckboxList('productos_raw', 'Producto Raw', $prod_raw);

                foreach ($prod_raw as $nivel)
                    //$this->form->addCheckboxList('productos_raw', 'Producto Raw', $prod_raw);


                    $this->form->addText('cantidad[]', 'Cantidad')
                            ->setAttribute('placeholder', 'Cantidad');

                    $this->form->addText('observaciones[]', 'Observaciones')
                            ->setAttribute('rows', 4)
                            ->setAttribute('placeholder', 'observaciones del producto vendido')
                            ->addRule(Form::MAX_LENGTH, 'Maximo de caracteres %d',250);


but tracy show me the next error


Component name must be non-empty alphanumeric string, ‘producto_id[]’ given

how can i made textfields with the same name into form classes, the differences one from another will be the attr ‘id’, for templates
thanks for the help

Last edited by alnux (2017-05-14 17:31)

15 days ago

Member | 550

You can't use names ending with [] for Nette form controls. You can however use form containers and then end up having input names like products[1][title], products[1][price], products[2][title], products[2][price], etc.
Check Form::addContainer() method.

If you insist on using the “[]” inputs, you still can, but instead of using Nette controls for them, you have to handle them via Form::getHttpData().

Last edited by duke (2017-05-14 19:25)

Board footer

Hostováno na e-infrastruktuře CESNET. Děkujeme za podporu sdružení CESNET, z.s.p.o.