How Do I Stop A Selected <select> Item Disappearing When the Options are Updated?

I have a select statement like this:

repeat attendees_datastore
   <select id="i_attendee_price" 
      dmx-bind:options="prices_datastore.data.where(attendee==$id).where(show_price==1)"
      dmx-on:changed="flow to update prices_datastore's values.">

With the logic of what I am creating, sometimes the dmx-on:changed causes the options available to the select statement to change, but still include the option the user has selected.

The problem is that when this happens, the user selected option disappears.

Is there something I can do or Wappler can do to prevent this?

Use Case

I have the following situation:

  • A booking form with some price options that are limited by the number of those prices that can be sold ("number limited prices").
  • Up to 6 people can book on a single pass through the booking form.

Hence if some of the people who book choose a "number limited price", I need to make sure I don't exceed the number available to book.

To manage this I have the prices in a data store, which lists each price for each attendee, and whether that price can be shown based on the number left available to book... something like this:

[attendee1, price1, show_price], [attendee1, price2,  show_price], [attendee2, price1,  show_price], [attendee2, price2  show_price], etc

If a user de-selects a number limited price, then I need to make it available again for the other users, hence changing the options available for the select statements.

When this happens, the item the user has selected disappears.

I don’t have an exact answer, but I think I know what you mean :slightly_smiling_face:

It looks like in your code you don’t have anything bindings set up for the value of the input, so it makes sense that I’d the underlying data changes for the select options it would default back to the top of the list of blank etc.

I’d think that there would be something you could add to the dmx-bind: value to get it working. Not sure what as I don’t know your data, but I’d start there. Perhaps a ternary operation of some kind

1 Like

That’s an interesting point @Philip_J

So, how do I use the dmx-bind:value? Should I store the selected value dmx-on:updated in a datastore and set that datastore value as the dmx-bind:value?

YIPPEE! I've done that and it's fixed the problem perfectly.

Thank you soooooo much @Philip_J! :partying_face:

Happy to point you in the right direction at least :slightly_smiling_face:

1 Like