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

Examples of setting defaults #2

Open
joshRpowell opened this issue Dec 1, 2022 · 3 comments
Open

Examples of setting defaults #2

joshRpowell opened this issue Dec 1, 2022 · 3 comments
Labels
good first issue Good for newcomers

Comments

@joshRpowell
Copy link

joshRpowell commented Dec 1, 2022

@BakiVernes fantastic component! thank you for sharing.

I'm trying to convert the following list of check_boxes to multiselect with default selections (as seen below, using checked). I tried experimenting with the traditional selected attribute without luck.

Perhaps I'm missing something subtle that could be added to documentation. Thanks in advance!

Screen Shot 2022-12-01 at 8 39 49 AM

In my example above I'm using the session to preserve the value.

@joshRpowell joshRpowell changed the title Examples of setting defaults and using session values Examples of setting defaults Dec 1, 2022
@BakiVernes
Copy link
Contributor

Thank you @joshRpowell for trying out our component. Indeed, the documentation is lacking in that regard and we will fix it. In the mean time here is the solution:

On the element that has the data-controller="multiselect" attribute add the following json array data-multiselect-selected-value="[{ "text": "Active", "value": 1 }]"

Your specific case:

<div data-controller="multiselect" data-multiselect-selected-value="[{ "text": "Active", "value": "whateverTheIdOrValueIs" }, { "text": "Contracted", "value": "whateverTheIdOrValueIs" }]" >

Tell me if this fixes your problem.

@BakiVernes BakiVernes added the good first issue Good for newcomers label Dec 6, 2022
@joshRpowell
Copy link
Author

@BakiVernes thanks for the quick response. Your suggestion works great! Working as expected. Thank you! Let me know if there is a direction you have in mind with documentation, I'd be happy to collaborate.

@BakiVernes
Copy link
Contributor

Since you seem interested I think it would be good to mention preselected values in the Good to know section of the documentation. I'll close this issue when you contribute. Thank you!

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

No branches or pull requests

2 participants