diff --git a/spoon/form/dropdown.php b/spoon/form/dropdown.php index a3b1b71..0f1a1eb 100644 --- a/spoon/form/dropdown.php +++ b/spoon/form/dropdown.php @@ -735,4 +735,16 @@ private function setValues(array $values = null) } } } + + /** + * Marks a field as required + * + * @return self + */ + public function makeRequired() + { + $this->setAttribute('required', 'required'); + + return $this; + } } diff --git a/spoon/tests/form/SpoonFormDropdownTest.php b/spoon/tests/form/SpoonFormDropdownTest.php index 136f541..91d59ce 100644 --- a/spoon/tests/form/SpoonFormDropdownTest.php +++ b/spoon/tests/form/SpoonFormDropdownTest.php @@ -161,4 +161,19 @@ public function testParse() { $this->ddmDefaultElement->parse(); } + + public function testRequired() + { + $this->ddmSingle->makeRequired(); + $this->assertEquals( + 'required', + $this->ddmSingle->getAttributes()['required'] + ); + + $this->ddmMultiple->makeRequired(); + $this->assertEquals( + 'required', + $this->ddmMultiple->getAttributes()['required'] + ); + } }