Skip to content

Commit 2aeabca

Browse files
committed
Container::addEmail(): added $maxLength=255 [Closes #303]
1 parent 7c7f9b5 commit 2aeabca

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/Forms/Container.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,13 @@ public function addTextArea(
354354
/**
355355
* Adds input for email.
356356
*/
357-
public function addEmail(string $name, string|Stringable|null $label = null): Controls\TextInput
357+
public function addEmail(
358+
string $name,
359+
string|Stringable|null $label = null,
360+
int $maxLength = 255,
361+
): Controls\TextInput
358362
{
359-
return $this[$name] = (new Controls\TextInput($label))
363+
return $this[$name] = (new Controls\TextInput($label, $maxLength))
360364
->addRule(Form::Email);
361365
}
362366

tests/Forms/Controls.TextInput.render.phpt

+12
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,15 @@ test('addFilter() & rules', function () {
258258

259259
Assert::same('<input type="text" name="text" id="frm-text" data-nette-rules=\'[{"op":":min","msg":"min","arg":1}]\'>', (string) $input->getControl());
260260
});
261+
262+
263+
test('addEmail', function () {
264+
$form = new Form;
265+
$input = $form->addEmail('email', 'Label');
266+
267+
Assert::type(Html::class, $input->getLabel());
268+
Assert::same('<label for="frm-email">Label</label>', (string) $input->getLabel());
269+
270+
Assert::type(Html::class, $input->getControl());
271+
Assert::same('<input type="email" name="email" maxlength="255" id="frm-email" data-nette-rules=\'[{"op":":email","msg":"Please enter a valid email address."}]\'>', (string) $input->getControl());
272+
});

tests/Forms/expected/Forms.renderer.1.expect

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<tr>
2828
<th><label for="frm-email">Email:</label></th>
2929

30-
<td><input type="email" name="email" id="frm-email" data-nette-rules='[{"op":":email","msg":"Please enter a valid email address."}]' data-nette-empty-value="&#64;" value="&#64;" class="text"></td>
30+
<td><input type="email" name="email" maxlength="255" id="frm-email" data-nette-rules='[{"op":":email","msg":"Please enter a valid email address."}]' data-nette-empty-value="&#64;" value="&#64;" class="text"></td>
3131
</tr>
3232
</table>
3333
</fieldset>

0 commit comments

Comments
 (0)