robsontenorio / mary

Laravel Blade UI Components for Livewire 3
https://mary-ui.com
Other
990 stars 117 forks source link

Choices in Forms #591

Closed flatcapco closed 1 month ago

flatcapco commented 1 month ago

When using a Livewire Form and the Choices field, it would be nice if we could place all the associated methods within the livewire form.

The options field works as expected, but because the search-function expects a string it doesn't resolve to the correct method if "searchFromAddress" is within a form

                <x-choices
                    :label="__('From Address')"
                    wire:model="form.from_address_id"
                    :options="$this->form->fromAddressSearchable"
                    search-function="searchFromAddress"
                    single
                    searchable/>

This would allow the only part of the forms customisation to simply be the fields and keeps the parent component cleaner

Thanks

robsontenorio commented 1 month ago

It tries to invoke a method that exists on your current component. I don't even know if Livewire allows you to invoke a function from another place.

Try this ... Livewire expects myFunction to be present on your current component . Am I wrong?

<buttton wire:click="myFunction">test</button>
flatcapco commented 1 month ago

I'll see if I can find any best practises on the livewire discord - but I've got a feeling you're right it just seems a shame to have access to a Form but not be able to group all the shared logic