Skip to content

Commit

Permalink
Merge pull request #574 from yaquawa/remove_fields
Browse files Browse the repository at this point in the history
Remove multiple fields with one call.
  • Loading branch information
kristijanhusak committed Jan 12, 2020
2 parents 9090e02 + 7d8d7fb commit 6dd28e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/Kris/LaravelFormBuilder/Form.php
Expand Up @@ -340,13 +340,15 @@ public function compose($class, array $options = [], $modify = false)
/**
* Remove field with specified name from the form.
*
* @param $name
* @param string|string[] $names
* @return $this
*/
public function remove($name)
public function remove($names)
{
if ($this->has($name)) {
unset($this->fields[$name]);
foreach (is_array($names) ? $names : func_get_args() as $name) {
if ($this->has($name)) {
unset($this->fields[$name]);
}
}

return $this;
Expand Down
5 changes: 3 additions & 2 deletions tests/FormTest.php
Expand Up @@ -448,11 +448,12 @@ public function it_can_remove_existing_fields_from_form_object()

$this->assertTrue($this->plainForm->has('name'));

$this->plainForm->remove('name');
$this->plainForm->remove('name', 'description');

$this->assertEquals(2, count($this->plainForm->getFields()));
$this->assertEquals(1, count($this->plainForm->getFields()));

$this->assertFalse($this->plainForm->has('name'));
$this->assertFalse($this->plainForm->has('description'));
}

/** @test */
Expand Down

0 comments on commit 6dd28e5

Please sign in to comment.