Skip to content

Commit b38ac91

Browse files
committed
Container: added addEmail() & addInteger()
1 parent 341e8a7 commit b38ac91

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/Forms/Container.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,34 @@ public function addTextArea($name, $label = NULL, $cols = NULL, $rows = NULL)
273273
}
274274

275275

276+
/**
277+
* Adds input for email.
278+
* @param string control name
279+
* @param string label
280+
* @return Controls\TextInput
281+
*/
282+
public function addEmail($name, $label = NULL)
283+
{
284+
return $this[$name] = (new Controls\TextInput($label))
285+
->setRequired(FALSE)
286+
->addRule(Form::EMAIL);
287+
}
288+
289+
290+
/**
291+
* Adds input for integer.
292+
* @param string control name
293+
* @param string label
294+
* @return Controls\TextInput
295+
*/
296+
public function addInteger($name, $label = NULL)
297+
{
298+
return $this[$name] = (new Controls\TextInput($label))
299+
->setRequired(FALSE)
300+
->addRule(Form::INTEGER);
301+
}
302+
303+
276304
/**
277305
* Adds control that allows the user to upload files.
278306
* @param string control name

tests/Forms/Forms.renderer.1.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<tr class="required">
1515
<th><label for="frm-age" class="required">Your age:</label></th>
1616

17-
<td><input type="number" name="age" id="frm-age" required data-nette-rules='[{"op":":filled","msg":"Enter your age"},{"op":":integer","msg":"Age must be numeric value"},{"op":":range","msg":"Age must be in range from 10 to 100","arg":[10,100]}]' min="10" max="100" class="text">
17+
<td><input type="number" name="age" id="frm-age" required data-nette-rules='[{"op":":filled","msg":"Enter your age"},{"op":":integer","msg":"Please enter a valid integer."},{"op":":range","msg":"Age must be in range from 10 to 100","arg":[10,100]}]' min="10" max="100" class="text">
1818

1919
<span class="error">
2020
Enter your age
@@ -31,7 +31,7 @@
3131
<tr>
3232
<th><label for="frm-email">Email:</label></th>
3333

34-
<td><input type="text" name="email" id="frm-email" data-nette-rules='[{"op":":filled","rules":[{"op":":email","msg":"Incorrect email address"}],"control":"email"}]' data-nette-empty-value="&#64;" value="&#64;" class="text"></td>
34+
<td><input type="email" name="email" id="frm-email" data-nette-rules='[{"op":"optional"},{"op":":email","msg":"Please enter a valid email address."}]' data-nette-empty-value="&#64;" value="&#64;" class="text"></td>
3535
</tr>
3636
</table>
3737
</fieldset>

tests/Forms/Forms.renderer.1.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,14 @@ $form->addGroup('Personal data')
4343
$form->addText('name', 'Your name:')
4444
->addRule(Form::FILLED, 'Enter your name');
4545

46-
$form->addText('age', 'Your age:')
46+
$form->addInteger('age', 'Your age:')
4747
->addRule(Form::FILLED, 'Enter your age')
48-
->addRule(Form::INTEGER, 'Age must be numeric value')
4948
->addRule(Form::RANGE, 'Age must be in range from %d to %d', [10, 100]);
5049

5150
$form->addRadioList('gender', 'Your gender:', $sex);
5251

53-
$form->addText('email', 'Email:')
54-
->setEmptyValue('@')
55-
->addCondition(Form::FILLED)
56-
->addRule(Form::EMAIL, 'Incorrect email address');
52+
$form->addEmail('email', 'Email:')
53+
->setEmptyValue('@');
5754

5855

5956
$form->addGroup('Shipping address')

0 commit comments

Comments
 (0)