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

Commit

Permalink
Support for ->required() on the label within a form group
Browse files Browse the repository at this point in the history
By intercepting the `required($conditional)` function here we will add automatically the `control-label-required` CSS class to the `<label>` HTML element.

This way you are able to use CSS to style the `<label>` HTML element however you want, you can even use pseudo-elements to add an asterisk:
```css
label.control-label-required:after {
    content: " *";
}
```

Obviously we wont interfere with Form Builder and we'll call the `required()` function defined within `adamwathan/form` no matter what. The CSS class will just be added conditionally.
  • Loading branch information
clemblanco committed Apr 25, 2017
1 parent f593c33 commit d94265c
Showing 1 changed file with 10 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

0 comments on commit d94265c

Please sign in to comment.