jeudi 16 juillet 2020

pre-select option value from drop down list

I have below code to select recipients.

<select class="form-control input-lg dm-recipients" id="recipients" name="recipients[]" multiple="multiple">
  <% if @di.size >= 1 and !@di.include?("data") %>
    <% @di.each do |d| %>
         <% @members.each do |user| %>    
             <% name = user['first'] + " " + user['last'] %>   
            <option value="<%= user["id"] %>"><%= name&.try(:strip) %></option> 
        <% end %>
    <% end %>
  <% end %>
</select>

Here I load all the members and I can select multiple members. My problem is how can I pre-select some values from the drop down base on a condition. As an example if user ID == member id I want to pre select it.

enter image description here

If logged in user is Darek I want to pre-select it. How can I do this?




Aucun commentaire:

Enregistrer un commentaire