如何使用Ruby on Rails将text_field必需属性设置为false以提交表单

时间:2019-05-06 04:27:10

标签: javascript html ruby-on-rails

我正在尝试提交带有循环text_field的表单。但是,每当我单击“提交”按钮时,都没有任何反应。每当用户从折扣下拉列表中单击VIP折扣时,就会显示VIP名称text_field。对于每张VIP票,都有一个VIP名称字段。 text_field是必需的。我正在尝试通过单击“购买”按钮来提交。 也许隐藏的text_Field上的必填字段正在生效,这就是表单无法提交的原因。每当隐藏.removeAttribute("required")时,我都尝试实现javascript .required = false;text_field,但效果不佳。你有什么想法

enter image description here

<%= f.fields_for :movie_tickets do |mtf| %>
  <div class="row text-center">
    <label>============================ <%= "TICKET " + @count.to_s %> =============================</label> <br> <br>
    <b> SEAT NO: <%=mtf.object.seat.name%> | ORIGINAL PRICE: <label class="label_original_prices"><%= number_to_currency mtf.object.net_price, unit:'' %></label> | DISCOUNTED PRICE: <label class="label_discounted_prices" id="pricediscount<%=@count%>">No Discount</label> </b> <br> <br>
  </div>

  <div class="form-group">
    <div class="col-md-3">
      <label>DISCOUNT :</label>
    </div>
    <div class="col-md-9">
      <%= mtf.select :discount_id, options_from_collection_for_select(discounts, :id,:name),{include_blank:true}, class:"form-control", id:"discount"+@count.to_s, onchange:"getDisc(this)" %>
    </div>
  </div>

  <br><br>

  <div class="form-group" style="display: none;" id="divVIP<%=@count%>">
    <div class="col-md-3">
      <label>VIP NAME :</label>
    </div>
    <div class="col-md-9">
      <%= mtf.text_field :vip_name , placeholder: "Type VIP name here...",class: "form-control", required: true %>
    </div>
  </div>
  <% @count += 1 %>
<% end %>

<script type="text/javascript">
  if(getValueDiscount == "9") {
    document.getElementById('divVIP' + count).style.display = "block";
  }else {
    document.getElementById('divVIP' + count).style.display = "none";
  }
</script>

1 个答案:

答案 0 :(得分:0)

在下一行中删除#define __STDC_WANT_LIB_EXT1__ 0 #include "header.h" #define __STDC_WANT_LIB_EXT1__ 1 #include "header.h" int main() {} 或将其设置为required: true

false