delayed composition of control – create it, add validation and then add it to a form

3 years ago

mikeb
Member | 30
+
0
-

hello
i'm creating forms dynamically based on data that specifies the form's structure.
every example i have found generates the control by attaching it to a form, like this:

$form = new Form;
$form->addText("name", "Your name")->setRequired(),

but I'd like to be able to generate the control, then modify it according to my criteria, then finally add it to the form. PSEUDO CODE:

$control = new textControl("name", "Your name");// i made this up...
$control->setRequired();
// ... do other stuff to $control ...
$form->addComponent($control, 'name');

But i can't figure out how to actually do this. any suggestions?

Thanks
Mike

3 years ago

CZechBoY
Member | 3379
+
0
-

Look at Nette\Forms\BaseControl extending classes https://api.nette.org/…Control.html