How to get state in and out of Livewire+alpinejs component in form? #15129
Unanswered
scottw-finao
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Package
Form builder
Package Version
v3.0.0
How can we help you?
I'm trying to build a google map Livewire component to help auto-fill a latitude and longitude text field but I can't seem to figure out the best practices for getting information into and out of the livewire piece. I've tried at least a dozen examples I found online to bind state and can't get any to work.
More detail:
I initially tried the locationclickr plugin (and a few others) but I need a very specific implementation of google maps as I need to set bounds on the area of the map and it's zoom out ability, and I also want to overlay the map with an existing hard-copy map the users will recognize.
The users I'm dealing with aren't very tech savvy so I wanted to have three different ways to specify a location:
Latitude and Longitude text fields
Visual (google maps) map you can click on
Upload of a KML waypoint file
I have the KML and lat/lon fields working fine, but I want to have the textfields update the map and a map-click update the text fields. (the map / location data from the map aren't hydrated directly, only the latitude/longitude fields are)
I've been banging my head on the keyboard for over a week trying to get this to work 'both ways' (map updating text fields, text fields updating map) and haven't made much progress on either. My main sticking point is trying to figure out how to bind/entangle/inject the state into the map and in turn get filament to know state has been updated on a map click event. (assuming I could bind/entangle state, I presume afterStateUpdated will trigger?)
Some of the sticky issues are things like:
Should I directly invoke the livewire component with a Livewire::make() in the Resource file or should I wrap the @livewire() in a custom field component in laravel? If one or the other, how do I pass state into the component in a way i can modify in the javascript code handling the map click event?
Most of the examples I see on the documentation are either lacking sufficient context/detail to know what goes where and how, or relate to html type directives and not calls in javascript code.
Most of the examples I see in the documentation are confusing when talking about Field components and Livewire components in the same breath. (the lack of context/detail makes it hard sometimes to tell what code examples refer to as far as context in the codebase)
I would post code examples but I'm so far from having anything remotely working and so confused as to how I do what and where, I'd probably just confuse the issue and myself more to post any iteration of the dozens of things I've tried.
What I can include is my map javascript. My desire would be to pass in 'state' as a parameter to the constructor so i could just update state.latitude and state.longitude or something similar to trigger afterStateChange
I tried the below as the blade template for the livewire component, but again, don't know how to bind the state to it:
x-load-js pulls the code from the AppManager registered as load when needed.
Beta Was this translation helpful? Give feedback.
All reactions