Skip to content

Commit

Permalink
Merge pull request #66 from Log1x/add-button-group
Browse files Browse the repository at this point in the history
Add Button Group field. Fixes #65
  • Loading branch information
stevep authored Aug 1, 2018
2 parents 5d80396 + 46d3528 commit e46d0fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/FieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ public function addCheckbox($name, array $args = [])
return $this->addChoiceField($name, 'checkbox', $args);
}

/**
* @param string $name
* @param array $args field configuration
* @throws FieldNameCollisionException if name already exists.
* @return FieldBuilder
*/
public function addButtonGroup($name, array $args = [])
{
return $this->addChoiceField($name, 'button_group', $args);
}

/**
* @param string $name
* @param array $args field configuration
Expand Down
27 changes: 26 additions & 1 deletion tests/FieldsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,31 @@ public function testAddCheckbox()
$this->assertArraySubset($expectedConfig, $builder->build());
}

public function testAddButtonGroup()
{
$builder = new FieldsBuilder('fields');
$builder->addButtonGroup('colors')
->addChoice('red')
->addChoice('blue')
->addChoice('green');

$expectedConfig = [
'fields' => [
[
'name' => 'colors',
'type' => 'button_group',
'choices' => [
'red' => 'red',
'blue' => 'blue',
'green' => 'green',
],
],
],
];

$this->assertArraySubset($expectedConfig, $builder->build());
}

public function testAddPostObject()
{
$builder = new FieldsBuilder('fields');
Expand Down Expand Up @@ -550,7 +575,7 @@ public function testAddGoogleMap()

$this->assertArraySubset($expectedConfig, $builder->build());
}

public function testAddLink()
{
$builder = new FieldsBuilder('fields');
Expand Down

0 comments on commit e46d0fb

Please sign in to comment.