maxmarcon / live_select

Dynamic (multi)selection field for LiveView
https://hex.pm/packages/live_select
Apache License 2.0
186 stars 35 forks source link

Selection not restored after focus+blur when value pre-selected or forced #81

Closed arconautishche closed 2 months ago

arconautishche commented 2 months ago

LiveSelect and LiveView versions LiveSelect: 1.4.2 LiveView: 0.20.17

Describe the bug If the value is pre-selected or sent via send_update then it does not reappear in the input after focus & blur.

Expected behavior The selected value should be there after focus & blur, even if it was set from the outside of the component.

Actual behavior The previous manually selected value is restored (or it stays empty, if no manual selection was performed).

Browsers Chrome, Safari

Additional context After looking through the code, I think I know what the fix could be - the update callback could use a socket = maybe_save_selection(socket) after applying the value from value or field assigns.

I'll try to get a PR with the suggested fix.

arconautishche commented 2 months ago

Here's the PR - #82 that fixes the issue. Thanks in advance for reviewing it.