update to nette 2.1 getLabelPart, getControlPart?

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
mcmatak
Člen | 504
+
0
-

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
+
-1
-

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
+
0
-

yes i know and these functions are the essential of the problem

i need to render all types of controls and these functions are known only on checkbox, not select, not text etc.

one-two
Člen | 80
+
0
-

How about this?

{if $control instanceof Checkbox}
...
{else}
standard way
{/if}
mcmatak
Člen | 504
+
0
-

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}