how can i made textfields with the same name into form classes
- alnux
- Member | 139
hi there im trying to build a forms with same name textfields as array ex: mytextfield[], here is what is talking about
$prod_raw=[
'{"1":3.5}'=>"Hielo grande",
'{"2":2.5}'=>"Hielo pequeño",
'{"3":3.5}'=>"Agua",
];
$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->addHidden('producto_id[]');
$this->form->addHidden('preciounitario[]');
$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
Nette\InvalidArgumentException
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)
- duke
- Member | 650
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)