Skip to content

Commit caaffff

Browse files
committed
Container::addInteger() is nullable
1 parent 98b743f commit caaffff

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Forms/Container.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public function addEmail($name, $label = NULL)
299299
public function addInteger($name, $label = NULL)
300300
{
301301
return $this[$name] = (new Controls\TextInput($label))
302+
->setNullable()
302303
->setRequired(FALSE)
303304
->addRule(Form::INTEGER);
304305
}

tests/Forms/Controls.TextInput.render.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,13 @@ test(function () { // rendering options
211211
$input->getControl();
212212
Assert::true($input->getOption('rendered'));
213213
});
214+
215+
216+
test(function () { // addInteger
217+
$form = new Form;
218+
$input = $form->addInteger('text');
219+
220+
Assert::null($input->getValue());
221+
222+
Assert::same('<input type="number" name="text" id="frm-text" data-nette-rules=\'[{"op":"optional"},{"op":":integer","msg":"Please enter a valid integer."}]\'>', (string) $input->getControl());
223+
});

0 commit comments

Comments
 (0)