Skip to content

Commit

Permalink
Container::addEmail(): added $maxLength=255 [Closes #303]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 22, 2024
1 parent 7c7f9b5 commit 2aeabca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Forms/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,13 @@ public function addTextArea(
/**
* Adds input for email.
*/
public function addEmail(string $name, string|Stringable|null $label = null): Controls\TextInput
public function addEmail(
string $name,
string|Stringable|null $label = null,
int $maxLength = 255,
): Controls\TextInput
{
return $this[$name] = (new Controls\TextInput($label))
return $this[$name] = (new Controls\TextInput($label, $maxLength))
->addRule(Form::Email);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Forms/Controls.TextInput.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,15 @@ test('addFilter() & rules', function () {

Assert::same('<input type="text" name="text" id="frm-text" data-nette-rules=\'[{"op":":min","msg":"min","arg":1}]\'>', (string) $input->getControl());
});


test('addEmail', function () {
$form = new Form;
$input = $form->addEmail('email', 'Label');

Assert::type(Html::class, $input->getLabel());
Assert::same('<label for="frm-email">Label</label>', (string) $input->getLabel());

Assert::type(Html::class, $input->getControl());
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());
});
2 changes: 1 addition & 1 deletion tests/Forms/expected/Forms.renderer.1.expect
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<tr>
<th><label for="frm-email">Email:</label></th>

<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>
<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>
</tr>
</table>
</fieldset>
Expand Down

0 comments on commit 2aeabca

Please sign in to comment.