Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Commit

Permalink
Merge pull request #49 from JerseyMilker/improve-element
Browse files Browse the repository at this point in the history
Element improvements.
  • Loading branch information
adamwathan committed Jun 10, 2015
2 parents d4ac77d + a72b700 commit b9f9a48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/AdamWathan/Form/Elements/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ protected function removeAttribute($attribute)
unset($this->attributes[$attribute]);
}

public function type()
{
return $this->attributes['type'];
}

public function data($attribute, $value)
{
$this->setAttribute('data-'.$attribute, $value);
Expand Down Expand Up @@ -55,7 +60,13 @@ public function removeClass($class)
if (! isset($this->attributes['class'])) {
return $this;
}

$class = trim(str_replace($class, '', $this->attributes['class']));
if ($class == '') {
$this->removeAttribute('class');
return $this;
}

$this->setAttribute('class', $class);
return $this;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/FormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,20 @@ public function testAgainstXSSAttacksInBoundModels()
$this->assertEquals($expected, $result);
}

public function testRemoveClass()
{
$expected = '<input type="text" name="food">';
$result = (string)$this->form->text('food')->addClass('sandwich pizza')->removeClass('sandwich')->removeClass('pizza');
$this->assertEquals($expected, $result);
}

public function testGetTypeAttribute()
{
$expected = 'radio';
$result = $this->form->radio('fm-transmission')->type();
$this->assertEquals($expected, $result);
}

private function getStubObject()
{
$obj = new stdClass;
Expand Down

0 comments on commit b9f9a48

Please sign in to comment.