1

У меня есть следующий Ruby:simple_form collection_Radio_buttons создает дополнительные метки

<%= simple_form_for @answer, url: presentation_survey_path(@presentation) do |f| %> 
       <%= f.collection_radio_buttons :option_id, @question.options_array, :first, :last, {label: false} do |b| %> 
    <div class="col-sm-4"> 
     <%= b.label(class: 'btn btn-large', style: 'margin-right: 20px; margin-left: 20px;') {b.radio_button(id: b.object.last, class: 'answer-input', style: 'display: none;') + b.text } %> 
    </div> 
<% end %> 

И это правильно генерации HTML за исключением того, что он порождает две метки:

<span> 
    <label for="answer_option_id_15"> 
     <div class="col-sm-4"> 
      <label class="btn btn-large" for="answer_option_id_15" style="margin-right: 20px; margin-left: 20px;"> 
       <input class="answer-input" id="Way too many" name="answer[option_id]" style="display: none;" type="radio" value="15" /> 
      Way too many 
      </label> 
     </div> 
    </label> 
</span> 

Это gennerating первый ярлык для некоторых причина. Я хочу только сохранить вторую. Ярлык: false не работает. Как мне избавиться от первого ярлыка?

+0

Согласно документам, вы поняли это правильно, но единственное различие заключается в том, что вы вводите прямой html в строки между ними. Можете ли вы отказаться от этого и посмотреть, что произойдет? Если это работает, попробуйте content_tag или попробуйте применить класс и стиль в js или css. –

ответ

7

Согласно docs:

Для флажков и переключателей вы можете удалить метку меняющейся boolean_style от значения по умолчанию: вложенный: рядный.

Кроме того, simple_form имеет некоторые варианты collection_radio_buttons, которые описаны в коде:

# Collection radio accepts some extra options: 
# 
# * checked => the value that should be checked initially. 
# 
# * disabled => the value or values that should be disabled. Accepts a single 
#     item or an array of items. 
# 
# * collection_wrapper_tag => the tag to wrap the entire collection. 
# 
# * collection_wrapper_class => the CSS class to use for collection_wrapper_tag 
# 
# * item_wrapper_tag   => the tag to wrap each item in the collection. 
# 
# * item_wrapper_class  => the CSS class to use for item_wrapper_tag 
# 
# * a block     => to generate the label + radio or any other component. 

В моей заходящего item_wrapper_tag к false и boolean_style в :inline случае сделал трюк, например:

<%= f.collection_radio_buttons :option_id, @question.options_array, :first, :last, boolean_style: :inline, item_wrapper_tag: false do |b| %> 
+0

спасибо! это сделало трюк – feitla

Смежные вопросы