From ad42d087a475b35f38d90f2f5d9f4d4eb79d8bf4 Mon Sep 17 00:00:00 2001 From: raveren Date: Thu, 18 Apr 2024 11:55:18 +0300 Subject: [PATCH] Add autocomplete attribute helper to the form element --- docs/general-usage/element-classes.md | 7 ++++--- src/Elements/Form.php | 2 ++ tests/Elements/FormTest.php | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/general-usage/element-classes.md b/docs/general-usage/element-classes.md index a7ec74f..6e037fc 100644 --- a/docs/general-usage/element-classes.md +++ b/docs/general-usage/element-classes.md @@ -52,6 +52,7 @@ echo Element::withTag('p')->text('This is the content!'); - `function acceptsFiles()` - `function action(?string $action)` +- `function autocomplete(bool|string $autocomplete = true)` - `function method(?string $method)` - `function novalidate($novalidate = true)` - `function target(string $target)` @@ -66,7 +67,7 @@ echo Element::withTag('p')->text('This is the content!'); ## `Input` -- `function autocomplete(?$autocomplete)` +- `function autocomplete(bool|string $autocomplete = true)` - `function autofocus(?$autofocus)` - `function checked($checked = true)` - `function disabled($disabled = true)` @@ -104,7 +105,7 @@ echo Element::withTag('p')->text('This is the content!'); ## `Select` -- `function autocomplete(?$autocomplete)` +- `function autocomplete(bool|string $autocomplete = true)` - `function autofocus(?$autofocus)` - `function disabled(?$disabled)` - `function isReadonly(?$readonly)` @@ -120,7 +121,7 @@ echo Element::withTag('p')->text('This is the content!'); ## `Textarea` -- `function autocomplete(?$autocomplete)` +- `function autocomplete(bool|string $autocomplete = true)` - `function autofocus()` - `function cols(int $cols)` - `function disabled(?$disabled)` diff --git a/src/Elements/Form.php b/src/Elements/Form.php index e26330e..9880d70 100644 --- a/src/Elements/Form.php +++ b/src/Elements/Form.php @@ -3,10 +3,12 @@ namespace Spatie\Html\Elements; use Spatie\Html\BaseElement; +use Spatie\Html\Elements\Attributes\Autocomplete; use Spatie\Html\Elements\Attributes\Target; class Form extends BaseElement { + use Autocomplete; use Target; protected $tag = 'form'; diff --git a/tests/Elements/FormTest.php b/tests/Elements/FormTest.php index 07a9173..00f4e56 100644 --- a/tests/Elements/FormTest.php +++ b/tests/Elements/FormTest.php @@ -26,6 +26,12 @@ Form::create()->acceptsFiles() ); +it('can create a form with a non-autocomplete attribute') + ->assertHtmlStringEqualsHtmlString( + '
', + Form::create()->autocomplete(false) + ); + it('can create a form with a novalidate attribute') ->assertHtmlStringEqualsHtmlString( '
',