![](/img/trans.png)
[英]how to disable a submit button if text_field is empty in ruby on rails?
[英]How to set text_field required attribute false to submit the form using Ruby on Rails
我正在尝试使用循环text_field
提交表单。 但每当我点击提交按钮时,什么也没发生。 只要用户从折扣下拉列表中单击VIP折扣,就会显示VIP名称text_field
。 对于每张VIP门票,都有一个VIP名称字段。 text_field
是必需的。 我正在尝试通过单击“购买”按钮来提交它。 也许隐藏的text_Field上的必填字段生效,这就是表单无法提交的原因 。 我试图实现javascript .removeAttribute("required")
和.required = false;
每当text_field
被隐藏但它也不起作用。 你觉得怎么样?
<%= 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>
删除required: true
或在下面的行中将其设置为false
:
<%= mtf.text_field :vip_name , placeholder: "Type VIP name here...",class: "form-control", required: true %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.