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 #132 from Claymm/master
Browse files Browse the repository at this point in the history
Support for ->required() on the label within a form group
  • Loading branch information
adamwathan authored Apr 26, 2017
2 parents f593c33 + ebd0986 commit 7f99288
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/AdamWathan/BootForms/Elements/GroupWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public function hideLabel()
$this->labelClass('sr-only');
return $this;
}

public function required($conditional = true)
{
if ($conditional) {
$this->formGroup->label()->addClass('control-label-required');
}

call_user_func_array([$this->target, 'required'], [$conditional]);
return $this;
}

public function inline()
{
Expand Down
11 changes: 11 additions & 0 deletions tests/BasicFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,17 @@ public function testCanHideLabels()
$this->assertEquals($expected, $result);
}

public function testRequiredLabels()
{
$expected = '<div class="form-group"><label class="control-label control-label-required" for="email">Email</label><input type="text" name="email" id="email" class="form-control" required="required"></div>';
$result = $this->form->text('Email', 'email')->required()->render();
$this->assertEquals($expected, $result);

$expected = '<div class="form-group"><label class="control-label" for="email">Email</label><input type="text" name="email" id="email" class="form-control"></div>';
$result = $this->form->text('Email', 'email')->required(false)->render();
$this->assertEquals($expected, $result);
}

public function testCanAddGroupClass()
{
$expected = '<div class="form-group test-class"><label class="control-label" for="email">Email</label><input type="text" name="email" id="email" class="form-control"></div>';
Expand Down

0 comments on commit 7f99288

Please sign in to comment.