How could I add an ICONE inside a SELECT in HAML

Asked

Viewed 329 times

1

Hello, I would like to add icons (from source, like bootstrap for example) inside a select field in HAML, at first I am doing so, would that be possible? I thought about using the bootstrap list-dropdown as a lame measure, but it also didn’t work out so well...

- icons = ["icon-world", "icon-star-twohdd-o", "icon-users"] 
    %label.control-label
      = Activity.ht("activity_status_situation")
    %select{style: 'max-width: 300px; min-width: 150px', name: 'icons_milestone'}
      - for icon in icons do
        %option{value: "#{icon}", type: "", selected: ("")}
          %i.#{icon}
    

Thanks in advance!

1 answer

1

I solved the problem as follows,

First, I added the scape line Markup,

  $(document).ready(function() {
    $(".js-select-icons").select2({
      minimumResultsForSearch: Infinity,
      escapeMarkup: function(m) { 
         return m; 
      }
    });
  });

Second, instead of closing with '<' and opening with '>' in select, it was opened with the HTML tag as follows:

   %select.js-select-icons{style: 'min-width: 50px', name: 'icons_milestone'}
  - for icon in icons do
     %option{value: "#{icon}", type: "", selected: ("")}
       = "&lt;i class='#{icon}'>&lt;/i>".html_safe

This way, it worked perfectly! And it stayed the following way,

inserir a descrição da imagem aqui

I hope it helps and it’s clear...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.