Skip to content

Commit 27f81f5

Browse files
Sebosekdg
authored andcommitted
SelectBox: it is checked that value is non-empty only if selectbox has any options [Closes #5]
1 parent a8d199b commit 27f81f5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Forms/Controls/SelectBox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function getControl()
104104
public function validate()
105105
{
106106
parent::validate();
107-
if (!$this->isDisabled() && $this->prompt === FALSE && $this->getValue() === NULL) {
107+
if (!$this->isDisabled() && $this->prompt === FALSE && $this->getValue() === NULL && $this->options) {
108108
$this->addError(Nette\Forms\Validator::$messages[self::VALID]);
109109
}
110110
}

tests/Forms/Controls.SelectBox.loadData.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ test(function() use ($series) { // Select
4141
});
4242

4343

44+
test(function() use ($series) { // Empty select
45+
$_POST = array('select' => 'red-dwarf');
46+
47+
$form = new Form;
48+
$input = $form->addSelect('select');
49+
50+
Assert::true( $form->isValid() );
51+
Assert::same( NULL, $input->getValue() );
52+
Assert::same( NULL, $input->getSelectedItem() );
53+
Assert::false( $input->isFilled() );
54+
});
55+
56+
4457
test(function() use ($series) { // Select with prompt
4558
$_POST = array('select' => 'red-dwarf');
4659

0 commit comments

Comments
 (0)