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

Commit

Permalink
Allow targeting different pieces of a form group
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Dec 2, 2015
1 parent 0e84e1a commit 782cbe3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/AdamWathan/BootForms/Elements/GroupWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
class GroupWrapper
{
protected $formGroup;
protected $target;

public function __construct($formGroup)
{
$this->formGroup = $formGroup;
$this->target = $formGroup->control();
}

public function render()
Expand Down Expand Up @@ -45,9 +47,27 @@ public function inline()
return $this;
}

public function group()
{
$this->target = $this->formGroup;
return $this;
}

public function label()
{
$this->target = $this->formGroup->label();
return $this;
}

public function control()
{
$this->target = $this->formGroup->control();
return $this;
}

This comment has been minimized.

Copy link
@jesseleite

jesseleite Feb 11, 2016

Contributor

Ohhhh dang, this is slick! Thanks @adamwathan

public function __call($method, $parameters)
{
call_user_func_array(array($this->formGroup->control(), $method), $parameters);
call_user_func_array([$this->target, $method], $parameters);
return $this;
}
}
11 changes: 11 additions & 0 deletions tests/BasicFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,17 @@ public function testRenderInputGroupWithOldInputAndError()
$this->assertEquals($expected, $result);
}

public function testModifyingDifferentElementsOfAFormGroup()
{
$expected = '<div class="form-group foo" data-foo="bar"><label class="control-label bar" for="email" data-bar="baz">Email</label><input type="text" name="email" id="email" class="form-control baz" data-baz="foo"></div>';
$result = $this->form->text('Email', 'email')
->group()->addClass('foo')->data('foo', 'bar')
->label()->addClass('bar')->data('bar', 'baz')
->control()->addClass('baz')->data('baz', 'foo')
->render();
$this->assertEquals($expected, $result);
}

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

0 comments on commit 782cbe3

Please sign in to comment.