Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addHtml on button stopped working #276

Closed
tomolas opened this issue Aug 26, 2021 · 4 comments
Closed

addHtml on button stopped working #276

tomolas opened this issue Aug 26, 2021 · 4 comments

Comments

@tomolas
Copy link

tomolas commented Aug 26, 2021

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>

@dg
Copy link
Member

dg commented Aug 27, 2021

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'));

@tomolas
Copy link
Author

tomolas commented Aug 27, 2021

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.

@dg
Copy link
Member

dg commented Aug 27, 2021

I know, I fixed it.

@tomolas
Copy link
Author

tomolas commented Aug 28, 2021

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants