question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add custom classes to individual options and callbacks to disable field on <b-form-select> component

See original GitHub issue

Is your feature request related to a problem? Please describe…

Not explicitly related to an issue, although it’d be a nice feature to have. Previously, while using a normal select field, I could do this to add a specific class to an individual option:

<select class="form-control" v-model="selected" :disabled="isSelectDisabled()">
	<option disabled>--- Select Something ---</option>
	<option
		v-for="option in myOptions"
		:value="option "
		:disabled="isOptionSelected(option)"
		:class="{'strikethrough':isOptionSelected(option)}"
	>
		{{ option.text }}
	</option>
</select>
<b-btn @click="selectOptionFromModel">Select Option</b-btn>

being isOptionSelected(option) a method in my component returning a boolean whether the option has been selected.

Now I’m using the BFormSelect component to pass an array of options so I don’t have to create the select myself. I have noticed that passing a callback to {disabled: myCallback} only evaluates when building the options object. It’d be great if that callback could be re-evaluated on an event. Also, I cannot pass a custom class anymore depending on the option being selected.

Describe the solution you’d like

For the disabled field, it’d be a good solution to allow a custom event being caught by the component so the callback assigned to this property can be re-evaluated when the even is fired (passing the option value as an argument).

For the custom classes, I’d suggest a optionClass property in the object that could accept the same values that can be passed to the :class="[...]" property. In the case of a callback being passed as condition to apply the class, the option value should be passed

Describe alternatives you’ve considered

Currently I am re’evaluating those callbacks when needed so I can enable/disable the options acordingly by finding them in the array of options and setting the disabled property to what I need. As for the custom classes, there isn’t much that can be done other than modifying the DOM with vanilla JS, which is a bad idea when using Vue, so I can live without those classes as long as the option is disabled.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tmorehousecommented, Mar 13, 2020

It would make the b-form-select more complex, just like it would make your own wrapper component more complex.

And doing a v-for to get you the layout you like is maybe two extra lines of template markup

<b-form-select v-bind="{ ...$props, options: null }" v-on="$listeners">
  <option v-for="opt in options" :key="opt.text" :class="opt.class" :value="opt.value">
    {{ opt.text}}
  </option>
</b-form-select>
0reactions
stale[bot]commented, Jun 18, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set custom select classes depending on the state ...
I need add class of active or disabled elements to list .select-options. How make with jquery? – z_u_l. Nov 30, 2018 at 0:19....
Read more >
Form Components - Form.io Documentation
A custom CSS class to add to this component. ... Disable this field on the form. ... A Text Area has the same...
Read more >
Angular Custom Form Controls - Complete Guide
In this guide, we are going to learn exactly how to take an existing custom form control component and make it fully compatible...
Read more >
ASP.NET Core Blazor forms and input components
Clear(); // Custom validation logic if (!holodeck.Options) { messageStore?.Add(() => holodeck.Options, "Select at least one."); } } private ...
Read more >
Advanced Callbacks | Dash for Python Documentation | Plotly
This example illustrates how you can show an error while keeping the previous input, using dash.no_update to update only some of the callback...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found