diff --git a/src/AdamWathan/BootForms/Elements/GroupWrapper.php b/src/AdamWathan/BootForms/Elements/GroupWrapper.php index 14b6254..6ea3a68 100644 --- a/src/AdamWathan/BootForms/Elements/GroupWrapper.php +++ b/src/AdamWathan/BootForms/Elements/GroupWrapper.php @@ -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() { diff --git a/tests/BasicFormBuilderTest.php b/tests/BasicFormBuilderTest.php index dac8839..c082738 100644 --- a/tests/BasicFormBuilderTest.php +++ b/tests/BasicFormBuilderTest.php @@ -528,6 +528,17 @@ public function testCanHideLabels() $this->assertEquals($expected, $result); } + public function testRequiredLabels() + { + $expected = '
'; + $result = $this->form->text('Email', 'email')->required()->render(); + $this->assertEquals($expected, $result); + + $expected = '
'; + $result = $this->form->text('Email', 'email')->required(false)->render(); + $this->assertEquals($expected, $result); + } + public function testCanAddGroupClass() { $expected = '
';