Forms {input} macro rendering getControlPart

Notice: This thread is very old.
Member | 124

I was trying to investigate how to render checkboxes separately without surrounding label using {input} macro to take advantage of adding attributes like {input mycheck class=>'myclass'} .

I have found that Nette\Bridges\FormsLatte::macroInput() renders getControlPart() method when there is a colon (optionally with arguments) after the control name (otherwise, it renders getControl().

{input mycheck:} produces $_form['mycheck']->getControlPart()

It resolved my problem – it really simply renders checkbox without label, however it seems a bit obscure and I don't like using code I don't understand. Especially, this is weird as:

  • other form controls have no getControlPart() method
  • from the macroInput() method it seems that it was originally intended to render only some parts of form control, because arguments after colon are passed to getControlPart(), like {input mycheck:foo} produces $_form['mycheck']->getControlPart('foo'), however the argument has no meaning for getControlPart function.

It seems to me that this is actually maybe some relic that remained in forms rendering code from past, which can accidentally now be used for something completely different – surpressing rendering label around checkbox.

So, my question is: what was the original intention of rendering getControlPart? Does it have some purpose, or is it actually accidental behavior? Shouldn't it be removed or done in some more intuitive way, like returning getControlPart() method to Nette\Forms\Controls\BaseControl and render simple checkbox with {input mycheck:plain} to make it less obscure?

Sorry, I was not sure if this would have clear answer as a question or be worth of discussion how to use forms this way, so please feel free to move/start new thread in discussions.