Skip to content

Commit

Permalink
Merge pull request #18 from kgrzelak/dev
Browse files Browse the repository at this point in the history
Update elements type set
  • Loading branch information
kgrzelak authored Jul 1, 2024
2 parents 8b978dd + 46c415f commit 4ac2df7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/BaseItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,25 @@ public function setName(string $name): static
return $this;
}

public function type(string $type): static
/**
* @description Set the type of the element
* @param string|null $type
* @return static
*/
public function type(?string $type = null): static
{
$this->attributes->setAttribute('type', $type);

return $this;
}

/**
* @deprecated Use type() instead
* @description Set the type of the element
* @param string|null $type
* @return static
*/
public function setType(?string $type = null): static
{
$this->attributes->setAttribute('type', $type);

Expand Down
14 changes: 14 additions & 0 deletions tests/FormInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,18 @@ public function testDontShowErrorsWhenDisabledInConfiguration(): void

$this->assertEquals('<input type="text" name="test" class="form-control">', $item);
}

public function testCanCreateInputWithCustomType(): void
{
$item = LaravelForm::input()->type('password');

$this->assertEquals('<input type="password" class="form-control">', $item);
}

public function testCanCreateInputWithoutType()
{
$item = LaravelForm::input()->type(null);

$this->assertEquals('<input class="form-control">', $item);
}
}

0 comments on commit 4ac2df7

Please sign in to comment.