Different outputs <label n:name> and {label} for Radiolist
- medhi
- Generous Backer | 255
Hey,
I found that for radiolist, {label color:black}
correctly
prints the label for the element with key black
, but
<label n:name="color:black" />
incorrectly prints the main
label for the whole radiolist, not for the element with key
black
.
Even the both syntaxes are analogous, result is different.
Is this a bug or a feature?
Last edited by medhi (2023-02-24 19:17)
- m.brecher
- Generous Backer | 872
@medhi
<label n:name=“color:black”> incorrectly prints the main label for the whole radiolist
Hi,
I made testing of your code and found that everything in latte works OK.
testing form:
public function createComponentTestForm(): Form
{
$form = new Form();
$form->addRadioList('color', 'Barva', ['black', 'white']);
return $form;
}
latte variant 1:
{form 'testForm'}
<label n:name="color:0"><input n:name="color:0">black</label> <!-- notice: $key is 0 not 'black' !! -->
{/form}
output html is OK:
<label for="frm-testForm-color-0">
<input type="radio" name="color" id="frm-testForm-color-0" value="0">
black
</label>
latte variant 2:
{form 'testForm'}
{label color:1}{input color:1}white{/label}
{/form}
output html is OK:
<label for="frm-testForm-color-1">
<input type="radio" name="color" id="frm-testForm-color-1" value="1">
white
</label>
It seems you have a bug in your code. If you cannot found it post here a full code documentation for further inspection – form, data, latte.
Also check the radio items data if you intend to use <label n:name=“color:black”>, the items data should look like [‘black’ ⇒ ‘black’, …], because in documentation Nette Forms is clearly defined using <label n:name=“$name:$key”>
Last edited by m.brecher (2023-02-20 18:12)
- medhi
- Generous Backer | 255
public function createComponentTestForm(): Form { $form = new Form(); $form->addRadioList('color', 'Barva', ['black', 'white']); return $form; }
You have wrong list definition, as according to the documentation, every key should have a value:
public function createComponentTestForm(): Form
{
$form = new Form();
$form->addRadioList('color', 'Barva', ['black' => 'černá', 'white' => 'bílá']);
return $form;
}
In this case, {label color:white /}
will output
bílá
(which is right), but
<label n:name="color:white">
will output Barva
(which is wrong).
- m.brecher
- Generous Backer | 872
@medhi
You have wrong list definition
I have used as a list of items php array:
['black', 'white']
which is identical with array defined like this:
[0 => 'black', 1 => 'white']
So in this list definition every key (integer) has different value.
I have tested your list definition
public function createComponentTestForm(): Form
{
$form = new Form();
$form->addRadioList('color', 'Barva', ['black' => 'černá', 'white' => 'bílá']);
return $form;
}
and all three variants of latte syntax – all correctly working:
{form 'testForm'}
<label n:name="color:black"><input n:name="color:black">černá</label>
{/form}
{form 'testForm'}
{label color:white}{input color:white}bílá{/label}
{/form}
{form 'testForm'}
{label color:white/}{input color:white}
{/form}
rendered html is correct
<form action="..." method="post" id="frm-testForm">
<label for="frm-testForm-color-black">
<input type="radio" name="color" id="frm-testForm-color-black" value="black">černá</label>
....
</form>
<form action="..." method="post" id="frm-testForm">
<label for="frm-testForm-color-white">
<input type="radio" name="color" id="frm-testForm-color-white" value="white">
bílá
</label>
....
</form>
<form action="..." method="post" id="frm-testForm">
<label for="frm-testForm-color-white">bílá</label>
<input type="radio" name="color" id="frm-testForm-color-white" value="white">
...
</form>
You can copy my code samples and confirm that also in your project it works OK !
Bug is somewhere in your code I guess.
- m.brecher
- Generous Backer | 872
@medhi
but <label n:name=“color:white”> will output Barva (which is wrong).
visible text in label must be rendered in this case by hand, Nette will not do it automatically, you render in your code wrong value – probably parameter $label which is caption of the whole set of radioList but you have to render value of one item from the list !!
{form 'testForm'}
<label n:name="color:black"><input n:name="color:black">{$caption}</label>
// you must set correctly $caption !!
{/form}
- medhi
- Generous Backer | 255
m.brecher wrote:
visible text in label must be rendered in this case by hand, Nette will not do it automatically, you render in your code wrong value – probably parameter $label which is caption of the whole set of radioList but you have to render value of one item from the list !!
This is what I am talking about. {label color:white /}
works as
expected, but <label n:name="color:white" />
does not, even
the syntax is analogous, so the result should be same.