Open edisonywh opened 3 years ago
The solution in #13 is to use phx-keyup
and then bubble event to parent LiveView (whichever module that use Backoffice.Resources
), and then the Resource's LiveView will call out to the FormComponent, which will update the corresponding fields in hidden_input
.
I am going to merge #13 for now but I will keep this issue open as I'd like to have more discussions surrounding it: how does the API feel to you? Or is this a valid enough usecase?
Rendering the LiveComponent isn't the hard part, but the hard part is in figuring out how to
handle_events
.The markup would look like this:
But users don't really get access to the FormComponent itself, so maybe we can define a generic fallback
handle_event
for FormComponent like so (pseudo code):This means that maybe we can have a bit more of a complex logic in our CustomField component, then just send over a normalized version that can be popped into the changeset.
For example, I have a
Listing
form that can belong to a singleNewsletter
. I would love to be able to have a typeahead & suggestion box for Newsletters while I'm typing, and then when I click on the value, I want it to store it to thenewsletter_id
field in theListing
changeset instead.Not sure how feasible this is
EDIT: It doesn't really seem possible because
phx-change
works on a form level, and we can't nestform
in HTML (correct me if I'm wrong).One way to do this is maybe via JS hooks?