How to disable select_tag hint in rails?

I decided that I could not find a better way to make drop-down lists and cross-browser support, I probably should just stick with select_tag. I need an invitation, so I created it.

Is it possible to forcefully disable an invitation so that the user cannot select it? Is there a better way to do this when it does not display an invitation in a drop down list?

+4
source share
2 answers

This works for me:

<%=

prompt = 'select person'

select_tag( 
  name = 'person', 
  options_for_select(
    @names_array.unshift(prompt),  #Add prompt string to front of array
    selected: prompt,
    disabled: prompt,
  )
) 

%>

Although it seems to me that the: prompt option for the select_tag () helper should create <option>one that is disabled by default, so you can simply write:

select_tag( 
  name = 'person', 
  options_for_select(@names_array),
  prompt: 'select name'
) 
0
source

Rails 4.1. , select_tag. , .

JavaScript: , . ( JQuery selectmenu.)

$('#select_menu_id').on('selectmenuchange', function() {
    if ($(this).val().length > 0) {
        $(this).closest('form').submit();
    }
})
0

Source: https://habr.com/ru/post/1533839/


All Articles