diff --git a/src/Nella/Forms/DateTime/DateInput.php b/src/Nella/Forms/DateTime/DateInput.php index 2c8652a..8e9a7a6 100644 --- a/src/Nella/Forms/DateTime/DateInput.php +++ b/src/Nella/Forms/DateTime/DateInput.php @@ -174,16 +174,18 @@ private function normalizeFormat($input) */ public function setRequired($message = TRUE) { - if (!is_bool($message) && !is_string($message)) { + if ($message !== FALSE && !is_string($message)) { throw new \Nette\InvalidArgumentException('Message must be string'); } parent::setRequired($message); - $this->addCondition(Form::FILLED) - ->addRule(function (DateInput $control) { - return $this->validateDate($control); - }, $message); + if ($message !== FALSE) { + $this->addCondition(Form::FILLED) + ->addRule(function (DateInput $control) { + return $this->validateDate($control); + }, $message); + } return $this; } diff --git a/src/Nella/Forms/DateTime/DateTimeInput.php b/src/Nella/Forms/DateTime/DateTimeInput.php index 80ac4e6..ce968e7 100644 --- a/src/Nella/Forms/DateTime/DateTimeInput.php +++ b/src/Nella/Forms/DateTime/DateTimeInput.php @@ -322,16 +322,18 @@ private function normalizeFormat($input) */ public function setRequired($message = TRUE) { - if (!is_bool($message) && !is_string($message)) { + if ($message !== FALSE && !is_string($message)) { throw new \Nette\InvalidArgumentException('Message must be string'); } parent::setRequired($message); - $this->addCondition(Form::FILLED) - ->addRule(function (DateTimeInput $control) { - return $this->validateDateTime($control); - }, $message); + if ($message !== FALSE) { + $this->addCondition(Form::FILLED) + ->addRule(function (DateTimeInput $control) { + return $this->validateDateTime($control); + }, $message); + } return $this; } diff --git a/tests/Nella/Forms/DateTime/DateInputTest.phpt b/tests/Nella/Forms/DateTime/DateInputTest.phpt index 91a1dc7..2347f70 100644 --- a/tests/Nella/Forms/DateTime/DateInputTest.phpt +++ b/tests/Nella/Forms/DateTime/DateInputTest.phpt @@ -264,7 +264,7 @@ class DateInputTest extends \Tester\TestCase { $control = $this->createControl(); - $control->setRequired(TRUE); + $control->setRequired('Required'); Assert::true($control->isRequired()); } diff --git a/tests/Nella/Forms/DateTime/DateTimeInputTest.phpt b/tests/Nella/Forms/DateTime/DateTimeInputTest.phpt index 716cf98..0d74e14 100644 --- a/tests/Nella/Forms/DateTime/DateTimeInputTest.phpt +++ b/tests/Nella/Forms/DateTime/DateTimeInputTest.phpt @@ -510,7 +510,7 @@ class DateTimeInputTest extends \Tester\TestCase { $control = $this->createControl(); - $control->setRequired(TRUE); + $control->setRequired('Required'); Assert::true($control->isRequired()); }