Skip to content

Commit

Permalink
🐛 Fix form method
Browse files Browse the repository at this point in the history
  • Loading branch information
siguici committed Aug 10, 2023
1 parent 69191eb commit 2fae59b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to [Sikessem's UI kit](https://github.com/sikessem/ui) will

## [v0.6.3](https://github.com/sikessem/ui/releases/tag/v0.6.3) - 2023-08-10

- [0.x] Fix form method
- [0.x] Fix selected option
- [0.x] Fix select option keys
- [0.x] Improve handling of component aliases
Expand Down
2 changes: 1 addition & 1 deletion res/views/components/form.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@tag('form', $attributes->merge([...compact('method', 'action'), 'enctype' => $hasFiles ? 'multipart/form-data' : false]))
@tag('form', $attributes->merge([...compact('action'), 'method' => $method === 'GET' ? $method : 'POST', 'enctype' => $hasFiles ? 'multipart/form-data' : false]))
@csrf
@method($method)
{{ $slot }}
Expand Down
1 change: 0 additions & 1 deletion src/Components/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function __construct(
public bool $hasFiles = false,
) {
$method = strtoupper($method);
$method === 'GET' ? $method : 'POST';
$parameters = (array) $parameters;
if (is_null($route)) {
/** @var string */
Expand Down
50 changes: 49 additions & 1 deletion tests/Feat/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,59 @@
'Input name required',
'</li>',
'</ul>',
'<form method="GET" action="#">',
'<form action="#" method="GET">',
'<input type="hidden" name="_token" value="">',
'<p >',
'Input name required',
'</p>',
'</form>',
], false);
});

it('should render GET form', function () {
$view = $this->withViewErrors([
'name' => 'Input name required',
])->blade('<s-form method="get"/>');

$view->assertSeeInOrder([
'<form action="#" method="GET">',
'<input type="hidden" name="_method" value="GET">',
'</form>',
], false);
});

it('should render POST form', function () {
$view = $this->withViewErrors([
'name' => 'Input name required',
])->blade('<s-form method="post"/>');

$view->assertSeeInOrder([
'<form action="#" method="POST">',
'<input type="hidden" name="_method" value="POST">',
'</form>',
], false);
});

it('should render PUT form', function () {
$view = $this->withViewErrors([
'name' => 'Input name required',
])->blade('<s-form method="put"/>');

$view->assertSeeInOrder([
'<form action="#" method="POST">',
'<input type="hidden" name="_method" value="PUT">',
'</form>',
], false);
});

it('should render DELETE form', function () {
$view = $this->withViewErrors([
'name' => 'Input name required',
])->blade('<s-form method="delete"/>');

$view->assertSeeInOrder([
'<form action="#" method="POST">',
'<input type="hidden" name="_method" value="DELETE">',
'</form>',
], false);
});

0 comments on commit 2fae59b

Please sign in to comment.