update to nette 2.1 getLabelPart, getControlPart?
- mcmatak
- Člen | 504
i am trying to update project to nette 2.1, but there is some problems
for example, i am trying to render form in template, i have option renderingType with value firstControl, it means that usually i render first label in column and sometime i need to render first the control part,
the code is
{elseif $formControl->getOption('renderingType') && $formControl->getOption('renderingType') == 'firstControl'}
<td>
{!$formControl->control}
<div class="info" n:ifset="$formControl->options['description']">{!$formControl->options['description']}</div>
</td>
<td style="font-weight:bold">
{if $formControl->getOption('helpWarning')}
{icon 'helpWarning', title=>array($formControl->getLabel(), $formControl->getOption('helpWarning'))}
{elseif $formControl->getOption('help')}
{icon 'help', title=>array($formControl->getLabel(), $formControl->getOption('help'))}
{/if}
{!$formControl->label}
</td>
the problem is that now if the control type is checkbox then control is rendered included label, so the label will not be rendered in second column, i can change it to getControlPart, but what if it is not checkbox type? so i need to check which type it is to render?
similar problem if i try to render in default way, label first then control in second column
{else}
<th n:block="#label">
{if $formControl->getOption('helpWarning')}
{icon 'helpWarning', title=>array($formControl->getLabel(), $formControl->getOption('helpWarning'))}
{elseif $formControl->getOption('help')}
{icon 'help', title=>array($formControl->getLabel(), $formControl->getOption('help'))}
{/if}
{!$formControl->label}:
</th>
<td n:block="#control">
{if isset($formControl->options['thumb'])}<span class="controlThumb"><img src="{$formControl->options['thumb']}" /></span>{/if}
{if isset($formControl->options['controlPrefix'])}<span class="controlPrefix">{$formControl->options['controlPrefix']}</span>{/if}
{!$formControl->control}
getLabel() on checkbox render nothing, and getControl() render both of them
- one-two
- Člen | 80
Migrating to version 2.1
- partially rendered radiolists using {input name:$key} and {label name:$key}
see https://doc.nette.org/…tions/to-2-1
& https://api.nette.org/…heckbox.html
and try getControlPart()
& getLabelPart()
- mcmatak
- Člen | 504
yes i did it this way, but it is not comfortable
{elseif $formControl->getOption('renderingType') && $formControl->getOption('renderingType') == 'firstControl'}
<td>
{if $formControl instanceof \Nette\Forms\Controls\Checkbox}
{var $formControlControl = $formControl->getControlPart()}
{else}
{var $formControlControl = $formControl->getControl()}
{/if}
{!$formControlControl}
<div class="info" n:ifset="$formControl->options['description']">{!$formControl->options['description']}</div>
</td>
<td style="font-weight:bold">
{if $formControl instanceof \Nette\Forms\Controls\Checkbox}
{var $formControlLabel = $formControl->getLabelPart()}
{else}
{var $formControlLabel = $formControl->getLabel()}
{/if}
{if $formControl->getOption('helpWarning')}
{icon 'helpWarning', title=>array($formControlLabel, $formControl->getOption('helpWarning'))}
{elseif $formControl->getOption('help')}
{icon 'help', title=>array($formControlLabel, $formControl->getOption('help'))}
{/if}
{!$formControlLabel}
</td>
{else}