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

Commit

Permalink
Merge f905bb8 into c4190c4
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed May 13, 2015
2 parents c4190c4 + f905bb8 commit 3bf158e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/AdamWathan/BootForms/BasicFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,31 @@ public function textarea($label, $name)

public function inlineCheckbox($label, $name, $checked = false)
{
$label = $this->builder->label($label)->addClass('checkbox-inline');
$control = $this->builder->checkbox($name);
$label = $this->builder->label($label)->after($control)->addClass('checkbox-inline');

if ($checked) {
$control->check();
} else {
$control->uncheck();
}

return $label->after($control);
$checkGroup = new CheckGroup($label);
$checkGroup->inline();

return $checkGroup;
}

public function inlineRadio($label, $name, $value = null)
{
$value = $value ?: $label;
$label = $this->builder->label($label)->addClass('radio-inline');
$control = $this->builder->radio($name, $value);
$label = $this->builder->label($label, $name)->after($control)->addClass('radio-inline');

return $label->after($control);
$checkGroup = new CheckGroup($label);
$checkGroup->inline();

return $checkGroup;
}

public function date($label, $name, $value = null)
Expand Down
13 changes: 12 additions & 1 deletion src/AdamWathan/BootForms/Elements/CheckGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
class CheckGroup extends FormGroup
{
protected $label;
protected $inline = false;

public function __construct(Label $label)
{
$this->label = $label;
}

public function render()
{
{
if ($this->inline === true) {
return $this->label;
}

$html = '<div';
$html .= $this->renderAttributes();
$html .= '>';
Expand All @@ -25,6 +30,12 @@ public function render()
return $html;
}

public function inline()
{
$this->inline = true;
return $this;
}

public function control()
{
return $this->label->getControl();
Expand Down
42 changes: 42 additions & 0 deletions tests/BasicFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,55 @@ public function testRenderInlineCheckbox()
$this->assertEquals($expected, $result);
}

public function testRenderInlineCheckboxWithChaining()
{
$expected = '<label class="checkbox-inline"><input type="checkbox" name="DJ" value="meal" chain="link" checked="checked">Checkit!</label>';
$result = $this->form->inlineCheckbox('Checkit!', 'DJ')->value('meal')->chain('link')->check()->render();
$this->assertEquals($expected, $result);
}

public function testRenderInlineCheckboxModifier()
{
$expected = '<label class="checkbox-inline"><input type="checkbox" name="terms" value="1">Agree to Terms</label>';
$result = $this->form->checkbox('Agree to Terms', 'terms')->inline()->render();
$this->assertEquals($expected, $result);
}

public function testRenderInlineCheckboxModifierWithChaining()
{
$expected = '<label class="checkbox-inline"><input type="checkbox" name="DJ" value="meal" chain="link" checked="checked">Checkit!</label>';
$result = $this->form->checkbox('Checkit!', 'DJ')->inline()->value('meal')->chain('link')->check()->render();
$this->assertEquals($expected, $result);
}

public function testRenderInlineRadio()
{
$expected = '<label class="radio-inline"><input type="radio" name="color" value="Red">Red</label>';
$result = $this->form->inlineRadio('Red', 'color')->render();
$this->assertEquals($expected, $result);
}

public function testRenderInlineRadioWithChaining()
{
$expected = '<label class="radio-inline"><input type="radio" name="colour" value="Canada Red" chain="link" checked="checked">Canada Red</label>';
$result = $this->form->inlineRadio('Canada Red', 'colour')->chain('link')->check()->render();
$this->assertEquals($expected, $result);
}

public function testRenderInlineRadioModifier()
{
$expected = '<label class="radio-inline"><input type="radio" name="color" value="Red">Red</label>';
$result = $this->form->radio('Red', 'color')->inline()->render();
$this->assertEquals($expected, $result);
}

public function testRenderInlineRadioModifierWithChaining()
{
$expected = '<label class="radio-inline"><input type="radio" name="colour" value="Canada Red" chain="link" checked="checked">Canada Red</label>';
$result = $this->form->radio('Canada Red', 'colour')->inline()->chain('link')->check()->render();
$this->assertEquals($expected, $result);
}

public function testFormOpen()
{
$expected = '<form method="POST" action="">';
Expand Down

0 comments on commit 3bf158e

Please sign in to comment.