Create Widget with Form
Hello - is it possible to create a widget that generates a form? How would I do this?
25 Replies
using the form builder
widgets are livewire components
you can add forms to them with the form builder
Should the class extend Widget or extend Component?
got it
extends Widget implements Forms\Contracts\HasForms
then use
and {{ $this->form }}
in the viewdont forget
$this->form->fill()
I want my form blank to start (expecting user input), but yes that's good to remember for autofilling with data. Thank you!
its mandatory in both cases, read the docs
it initialises the form for use as well as filling it. if you dont use it, stuff like selects and file uploads wont work properly
Oh thank you I missed that
@danharrin using
$this->form->fill()
throws an error, Method App\Filament\Widgets\TeamQuickAccess::form does not exist
. But when I remove it everything works fine, including my form
And when the user submits the form, the data is correct without using fill
please send the entire widget code
View:
Is there a way to add the submit button as a part of
getFormSchema
? It can be kind of a pain to get the styling/spacing right for the submit button when it's separate like that$this->form->fill()
not $this->form()->fill()
Ah thank you!
Any idea on the submit button?
youre doing it right
Weird. It currently looks like this
Why does it show up outside of the card?
because its not in the form, but the card is
actually
i dont know why its not in the other card
thats weird
maybe wrap the button in a div?
i think its the float-right
dont do that
<div class="flex items-center justify-end">
Wow yup you were right
Why does that mess it up?
because floats are bad
lol
haha ok fair enough
working perfectly now
thank you!
you need a <form> element too
wrapping
{{ $this->form }}
?<form wire:submit.prevent="submit">
<x-filament::button type="submit" NO WIRE CLICK>
wrap the button and form, or just the cardoh ok. wire:click seemed to work
why change it?
because this way has browser validation
and also the ability to hit enter with any field and submit the form
Got it. Yes, both great features to make sure are included
Thank you!