Skip to content

Commit

Permalink
Merge pull request #36 from jonasdekeukelaere/dropdown-required
Browse files Browse the repository at this point in the history
Add shorthand to make dropdown required
  • Loading branch information
WouterSioen committed May 30, 2016
2 parents 6eb6865 + 11eeb3b commit f7a2fb8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spoon/form/dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
15 changes: 15 additions & 0 deletions spoon/tests/form/SpoonFormDropdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}
}

0 comments on commit f7a2fb8

Please sign in to comment.