html – 带有必填字段的Rails下拉菜单

前端之家收集整理的这篇文章主要介绍了html – 带有必填字段的Rails下拉菜单前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试调整现有的@R_404_382@设置菜单,以便我可以预先确定某些字段,例如性别与下拉选项,而不是用户必须输入.
目前的代码如下,
<%= form_for @profile,html: {multipart: true},url: profile_path do |f| %>

  <div class="col-md-6">

    <div class="form-group">
      <%= f.text_field :firstname,required: true,placeholder: 'Firstname',class: 'form-control' %>
    </div>


    <div class="form-group">
      <%= f.text_field :lastname,placeholder: 'Lastname',class: 'form-control' %>
    </div>

      <div class="form-group">
      <%= f.date_field :dob,placeholder: 'Date of Birth',class: 'form-control' %>
    </div>

    <div class="form-group">
      <%= f.text_field :contactnr,placeholder: 'Contact Number',class: 'form-control' %>
    </div>

    <div class="form-group">
      <%= f.text_field :address1,placeholder: 'Address Line 1',class: 'form-control' %>
    </div>

    <div class="form-group">
      <%= f.text_field :address2,placeholder: 'Address Line 2',class: 'form-control' %>
    </div>

    <div class="form-group">
      <%= f.text_field :town,placeholder: 'Town',class: 'form-control' %>
    </div>

    <div class="form-group">
      <%= f.text_field :county,placeholder: 'County',class: 'form-control' %>
    </div>

    <div class="form-group">
      <%= f.text_field :country,placeholder: 'Country',class: 'form-control' %>
    </div>

    <div class="form-group">
      <%= f.text_field :postcode,placeholder: 'Postcode',class: 'form-control' %>
    </div>

    <div class="form-group">
      <%= f.text_field :gender,placeholder: 'Gender',class: 'form-control' %>
    </div>

    <form action="">
      <input type="radio" name="sex" value="Male">Male<br>
      <input type="radio" name="sex" value="Memale">Female
    </form>

  </div>

  <div class="col-md-6">

    <div class='uploaded-pic'>
      <%= image_tag @profile.image.url(:medium) %>
    </div>

    <div class="form-group">
      <%= f.file_field :image %>
    </div>

    <%= f.submit class: 'btn btn-success' %> </p>

  </div>

<%end%>

具体来说,我想创建以下两段代码的某种混合,以便用户可以在下拉列表中选择一个值,然后在提交表单时保存该值.

<div class="form-group">
          <%= f.text_field :gender,class: 'form-control' %>
        </div>

        <form action="">
          <input type="radio" name="sex" value="Male">Male<br>
          <input type="radio" name="sex" value="Memale">Female
        </form>

解决方法

您可以使用这样的选择
<%= f.select :gender,%w{Male Female},:prompt => 'Select',class: 'form-control' %>

有关详细信息,请参阅此API.

原文链接:https://www.f2er.com/html/223779.html

猜你在找的HTML相关文章