Disable an option in a form select when dynamic

Does anyone know if it is possible to disable a few options in a form select like this

<select id="cars">
  <option value="volvo" disabled>Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw">VW</option>
  <option value="audi">Audi</option>
</select>

When the select is populated dynamically?

Don’t add the dynamic options to the select element in the typical manner, instead add a single option element and add a repeat to the option. Then you can use dmx-bind:disabled.

I did this with show/hide but should be the same for disabled.

1 Like

You could also use a datastore and either remove the item or flag it as Ken says as disabled and add a dmx-hide or disable

Actually I have done this a few times. I simply used the dynamic attribute display and hide when a criteria is met.

Edit: Actually, just re-read your original post. I see you are populating the select dynamically. My method likely won’t work.

Some great suggestions all, thanks you so much. @ben I did use tagify first, and it did work well, it’s just strange as a UI considering each select only allows one item to be selected, but yes that did work well.
@mebeingken, this extends the other topic where all were chatting about refinements and bug fixes, this would be a good one to go on the list of things that would be nice to be able to do the dynamic selects.

Such an awesome community, love this forum, ask a question and get so many great suggestions.

1 Like