Hi everyone. Really appreciate this library and it’s been really useful and simple to use. I have found myself wanting slightly more complex use case that helps show the user a “Create option”, when we find something typed that does not exist. I’m using live_select with user_defined_options={true} to allow users to create new items by typing text that doesn’t match existing options but I feel like it could be better UX to make it more visual.
This works great, but I’m finding myself repeating the same pattern in every
```elixir
handle_event(“live_select_change”, …) handler:
def handle_event(“live_select_change”, %{“id” => “project_select”, “text” => text} = params, socket) do
base_options = get_options(socket)
filtered = filter_by_text(base_options, text)
# Add "Create" option if no match
options = if text != "" && !exact_match?(base_options, text) do
[{"Create \"#{text}\"", text} | filtered]
else
filtered
end
send_update(LiveSelect.Component, id: params["id"], options: options)
{:noreply, socket}
end
Is there a recommended pattern for making this reusable? Ideally, I’d like to configure which LiveSelects should have this behavior and have the logic happen automatically, rather than writing the same handler for each select.
Has anyone implemented something like a behavior module or component wrapper that handles this generically? I think this pattern trips me up because it wants to hook into the handle_event so I’m thinking of using attach_hook but I can’t use that since I’d need to make sure that the option does not exist






















