Skip to content

Commit 800df9b

Browse files
committed
FormMacros: <label n:name></label> is rendered without caption, fixes 6d16631
1 parent 48fd7a4 commit 800df9b

File tree

8 files changed

+12
-3
lines changed

8 files changed

+12
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"nette/di": "~2.3",
2424
"nette/tester": "~1.3",
25-
"latte/latte": "~2.3",
25+
"latte/latte": "~2.3, >=2.3.2",
2626
"tracy/tracy": "~2.2"
2727
},
2828
"conflict": {

src/Bridges/FormsLatte/FormMacros.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
197197
if ($tagName === 'form') {
198198
$node->content = $parts[1] . $parts[2] . '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form, FALSE) ?>' . $parts[3];
199199
} elseif ($tagName === 'label') {
200-
if ($parts[2] === '') {
200+
if ($node->htmlNode->isEmpty) {
201201
$node->content = $parts[1] . '<?php echo $_input->getLabel()->getHtml() ?>' . $parts[3];
202202
}
203203
} elseif ($tagName === 'button') {
204-
if ($parts[2] === '') {
204+
if ($node->htmlNode->isEmpty) {
205205
$node->content = $parts[1] . '<?php echo htmlspecialchars($_input->caption) ?>' . $parts[3];
206206
}
207207
} else { // select, textarea

tests/Forms.Latte/expected/FormMacros.button.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
description of button
44
</button>
55

6+
<button type="submit" name="send" value="Sign in"></button>
7+
68
<button type="submit" name="send" value="Sign in">Sign in</button>
79
%A%
810
</form>

tests/Forms.Latte/expected/FormMacros.button.phtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
description of button
77
</button>
88

9+
<button<?php $_input = $_form["send"]; echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>></button>
10+
911
<button<?php $_input = $_form["send"]; echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>
1012
><?php echo htmlspecialchars($_input->caption) ?></button>
1113
<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form, FALSE) ?></form>

tests/Forms.Latte/expected/FormMacros.forms.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<LABEL title=hello for="frm-username">Name</LABEL>
5151
<input value=val type class="hello" name="username" id="frm-username">
5252

53+
<label for="frm-username"></label>
5354
<label for="frm-username">Username:</label>
5455
<input type="text" name="username" id="frm-username">
5556

tests/Forms.Latte/expected/FormMacros.forms.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
3434
'class' => NULL,
3535
))->attributes() ?>>
3636

37+
<label<?php $_input = is_object($form['username']) ? $form['username'] : $_form[$form['username']]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
3738
<label<?php $_input = is_object($form['username']) ? $form['username'] : $_form[$form['username']]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>
3839
><?php echo $_input->getLabel()->getHtml() ?></label>
3940
<input<?php $_input = is_object($form['username']) ? $form['username'] : $_form[$form['username']]; echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>>

tests/Forms.Latte/templates/forms.button.latte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
</button>
55

66
<button n:name="send"></button>
7+
8+
<button n:name="send" />
79
</form>

tests/Forms.Latte/templates/forms.latte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<input value=val type class="hello" n:name="username">
1818

1919
<label n:name="$form['username']"></label>
20+
<label n:name="$form['username']" />
2021
<input n:name="$form[username]">
2122

2223
{label my/}{input my}

0 commit comments

Comments
 (0)