Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing value instead of label on single search #59

Closed
renews opened this issue Feb 24, 2024 · 12 comments
Closed

Showing value instead of label on single search #59

renews opened this issue Feb 24, 2024 · 12 comments

Comments

@renews
Copy link

renews commented Feb 24, 2024

If a field comes from the database, instead of showing the value from the label, it is showing from the value.

For example, when considering the map below:
%{label: "test", value: "1"}
In the search it would appear correctly as test,
When the data is saved and reload using the data from the db it shows as 1

The dropdown search continues working as it should.

Step 1

image

Step 2

image

Step 3

Save the record

Step 4

The issue appears
image

@maxmarcon
Copy link
Owner

@renews When you load the data from the db, you need to map the data to an option that has name and label.

This is currently cumbersome to do, I'm working on a feature that will make it easier.

Tracked here: #55

@renews
Copy link
Author

renews commented Feb 26, 2024

What exactly do you mean? I already return it like a value ID for the DB like I posted on the example %{label: "test", value: "1"} even when I do this I have to do the value remap? like value_mapper={fn %Item{label: name, value: id} -> %{label: name, value: id} end} ?

@maxmarcon
Copy link
Owner

maxmarcon commented Feb 26, 2024

Oh yes you're right, I forgot you also need to set the options:

send_update(LiveSelect.Component, id: live_select_id, options:[%{label: name, value: id} .. ])

after you load the data from the DB

live select tries to match the value %{label: name, value: id} against the available list of options to find the label. But when you load fresh data from the DB the list of options is empty.

Again, you could argue that the label is there in the selected value, so it should use that one. I'll try to find time to work on these issues with structs and maps soon

@renews
Copy link
Author

renews commented Feb 26, 2024

Thank you for taking the time to look into it. Great work BTW

@renews
Copy link
Author

renews commented Feb 26, 2024

Also, its not about thesend_update since I already had it in place and that loads the same content from when we are search for the item. I think im not being clear and im sorry for that. The issues presents itself only when I leave the page with the live_select and come back later.

So if, the live_select already have some value on it when you load the page, it shows the ID, I will try to do something with the value_mappers and let you know

@maxmarcon
Copy link
Owner

warning: value_mappers are not implemented yet :) it was just brainstorming for an idea

@renews
Copy link
Author

renews commented Feb 26, 2024

warning: value_mappers are not implemented yet :) it was just brainstorming for an idea

Thx for the heads up haha :)

@hunterboerner
Copy link

I'm having the same issue here. Can we reopen the ticket?

@maxmarcon
Copy link
Owner

@caiohsr14
Copy link

This happens here in an inconsistent manner, sometimes it grabs the correct label and sometimes it grabs the value as the label. I have played around value_mapper and a few other things but to no avail.
Any ideas here? I can provide some more context here if needed, from what I can tell it might be the js hook receiving the wrong values from time to time

@maxmarcon
Copy link
Owner

@caiohsr14 this sounds like some kind of race condition to me. If you share your code, I can take a look

@caiohsr14
Copy link

caiohsr14 commented Nov 20, 2024

@caiohsr14 this sounds like some kind of race condition to me. If you share your code, I can take a look

Turns out after some debugging (and understanding more the framework), it was just some misusage of push_patch in my change event that was causing the issues. I have then updated the code and it works fine now
Thanks for the lib by the way!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants