You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ A set of Blade components to rapidly build forms with [Tailwind CSS Custom Forms
14
14
* Support for [Tailwind CSS Custom Forms](https://tailwindcss-custom-forms.netlify.app) and [Bootstrap 4 Forms](https://getbootstrap.com/docs/4.0/components/forms/).
15
15
* Component logic independent from Blade views, the Tailwind and Bootstrap views use the same logic.
16
16
* Bind a target to a form (or a set of elements) to provide default values.
17
+
* Support for [Laravel Livewire](https://laravel-livewire.com)
17
18
* Support for Spatie's [laravel-translatable](https://github.com/spatie/laravel-translatable).
18
19
* Re-populate forms with [old input](https://laravel.com/docs/master/requests#old-input).
19
20
* Validation errors.
@@ -159,6 +160,51 @@ You can override the `@bind` directive by passing a target directly to the eleme
159
160
</x-form>
160
161
```
161
162
163
+
#### Laravel Livewire
164
+
165
+
You can use the `@wire` and `@endwire` directives to use bind a form to a Livewire component. Let's take a look at the `ContactForm` example from the official Livewire documentation.
166
+
167
+
```php
168
+
use Livewire\Component;
169
+
170
+
class ContactForm extends Component
171
+
{
172
+
public $name;
173
+
public $email;
174
+
175
+
public function submit()
176
+
{
177
+
$this->validate([
178
+
'name' => 'required|min:6',
179
+
'email' => 'required|email',
180
+
]);
181
+
182
+
Contact::create([
183
+
'name' => $this->name,
184
+
'email' => $this->email,
185
+
]);
186
+
}
187
+
188
+
public function render()
189
+
{
190
+
return view('livewire.contact-form');
191
+
}
192
+
}
193
+
```
194
+
195
+
Normally you would use a `wire:model` attribute to bind a component property with a form element. By using the `@wire` directive, this package will automatically use the `wire:model` attribute instead of the `name` attribute.
196
+
197
+
```blade
198
+
<x-form wire:submit.prevent="submit">
199
+
@wire
200
+
<x-form-input name="name" />
201
+
<x-form-input name="email" />
202
+
@endwire
203
+
204
+
<x-form-submit>Save Contact</x-form-submit>
205
+
</form>
206
+
```
207
+
162
208
### Select elements
163
209
164
210
Besides the `name` attribute, the `select` element has a required `options` attribute, which should be a simple *key-value* array.
0 commit comments