addHtml on button stopped working
tomolas opened this issue · comments
Version: 3.1.4
Bug Description
Setting custom html content for a submit button in a form stopped working. The button from example below is rendered empty in v3.1.4 and is rendered as expected in v3.1.3 We sometimes set html inside a button to e.g. add an icon as a specially styled span element.
Steps To Reproduce
<?php
$form = new \Nette\Forms\Form('form');
$form->addText('dummyText', 'Type anything:');
$submit = $form->addSubmit('submit', NULL);
$button = $submit->getControlPrototype();
$button->setName("button");
$button->addHtml(Nette\Utils\Html::el('span')->setText('Submit me'));
echo $form;
if ($form->isSuccess()) {
echo "<pre>Values: \n";
print_r($form->getValues());
}
Expected Behavior
I would expect the "Submit me" text to appear inside a button element rendered like this: <button><span>Submit me</span></button>
The output from the code above in v3.1.3 is:
<form action="" method="post" id="frm-form">
<table>
<tr>
<th><label for="frm-form-dummyText">Type anything:</label></th>
<td><input type="text" name="dummyText" id="frm-form-dummyText" class="text"></td>
</tr>
<tr>
<th></th>
<td><button type="submit" name="_submit"><span>Submit me</span></button></td>
</tr>
</table>
<input type="hidden" name="_form_" value="form"><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->
</form>
in v 3.1.4 is:
<form action="" method="post" id="frm-form">
<table>
<tr>
<th><label for="frm-form-dummyText">Type anything:</label></th>
<td><input type="text" name="dummyText" id="frm-form-dummyText" class="text"></td>
</tr>
<tr>
<th></th>
<td><button type="submit" name="_submit"></button></td>
</tr>
</table>
<input type="hidden" name="_form_" value="form"><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->
</form>
It is related to #273. I didn't anticipate this use, a possible workaround is:
$form->addSubmit('submit', Nette\Utils\Html::el('span')->setText('Submit me'));
Thank you for the workaround.
It works correctly in v3.1.4 and produces:
<button type="submit" name="_submit"><span>Submit me</span></button>
But it does NOT work in v3.1.3 and produces:
<input type="submit" name="_submit" value="<span>Submit me</span>" class="button">
This clearly is a breaking change.
I know, I fixed it.
Thank you very much!