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

How do I hide empty option values with classes? #874

Open
ghost opened this issue Aug 11, 2021 · 3 comments
Open

How do I hide empty option values with classes? #874

ghost opened this issue Aug 11, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 11, 2021

What is the current behavior?

My empty value tags still appear in the ui.

I put style="display:none;" in the option tag.
I put option[value=""] {display: none;} in the style sheet

I even tried using the hidden attribute

What is the expected behavior?

I want to hide an option tag with empty value. Is there a custom css class I need to use?

@mlh758
Copy link
Collaborator

mlh758 commented Aug 11, 2021

You might consider using the removeOption method on the widget. The options that are rendered are li tags not option tags. The widget just uses the option tags from the original select to build the list before the widget takes the place of and hides the underlying select.

Otherwise you might try using css to hide li tags with no text that are under the ui-multiselect-checkboxes css class.

@ghost
Copy link
Author

ghost commented Aug 13, 2021

You might consider using the removeOption method on the widget. The options that are rendered are li tags not option tags. The widget just uses the option tags from the original select to build the list before the widget takes the place of and hides the underlying select.

Otherwise you might try using css to hide li tags with no text that are under the ui-multiselect-checkboxes css class.

Otherwise you might try using css to hide li tags with no text that are under the ui-multiselect-checkboxes css class.

This seems my best option I didn't know it rendered in li tags. So the css would then be
ui-multiselect-checkboxes li[value=""] {display: none'}

@mlh758
Copy link
Collaborator

mlh758 commented Aug 13, 2021

If you inspect the HTML on the demo page, it's not the li that has a value but the input tag underneath it. You'd end up with a selector like 'li input[value=""]'. That selects the checkbox though. You would need some JavaScript to hide the parent based on that since I don't think css has a parent selector.

Something like: document.querySelectorAll('li input[value=""]').forEach((el) => el.closest('li').className = "hidden")

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

1 participant