【问题标题】:how make input text field like an option of radio button wit simple_form如何使用 simple_form 使输入文本字段像单选按钮的选项
【发布时间】:2016-02-02 15:36:46
【问题描述】:

如何使用 simple_form gem Rails 为选项单选按钮组呈现输入字段?

我正在尝试渲染选项“其他”输入字段,见下文: <%= f.collection_radio_buttons :options, [["first_option", "Option 1"], ["second_option", "Option 2"], ["other", "<input type='text' name='other_reason' />" ]], :first, :last %> 基本上我正在尝试重现 http://jsfiddle.net/j08691/pgyA2/ 但使用 simple_form。

【问题讨论】:

    标签: ruby-on-rails radio-button simple-form


    【解决方案1】:

    试试下面的代码。

      $("reason_input").keyup(function(){
                    $("hidden_radio").val($(this).val())
                  })
    
    
    
              <%= f.radio_button_tag 'reason', "Fit Description" %>
              <%= f.radio_button_tag 'reason', "Suspicious Behavior" %>
              <%= f.radio_button_tag 'reason', "No Reason Given" %>
              <%= f.radio_button_tag 'reason', "Other" %>
              <%= f.radio_button_tag 'reason', nil, :id => :hidden_radio, :style => "display:none" %>
              <%= text_field :reason_input, :id => :reason_input %>
    

    【讨论】:

    • 你从哪里得到reason_input?这需要是数据库中的另一个属性吗?
    猜你喜欢
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2015-11-11
    • 1970-01-01
    • 2012-08-25
    • 2018-07-23
    • 2016-04-04
    相关资源
    最近更新 更多