Better using custom form controls
Notice: This thread is very old.
- Budry
- Member | 88
Hi,
I need very often use custom form controls (datepicker, antispam or some next for example) but if I can use in form I “must” create custom base form and extends Nette\Application\UI\Form or use a similiar code for register custom control (it is only example code, code is from a very old project and I'm not sure if is possible use in latest versions)
/**
* @param string $name
* @param string $class
*/
private function addExtension($name, $class)
{
\Nette\Forms\Container::extensionMethod($name, function (\Nette\Forms\Container $container, $name, $label = null) use ($class) {
return $container[$name] = new $class($label);
});
}
It is bad in my opition. More better will be add method for add custom form controls.
Example:
$form = new Form();
// or some better name for method
$form->addControl('name', new MyInput('label', /*... some next arguments..*/))
->....
I would like heard your opinions about this…
Last edited by Budry (2014-05-02 01:23)
- David Matějka
- Moderator | 6445
you can do
$form['name'] = new MyInput
//or
$form->addComponent(new MyInput, 'name');