如果用户未填写以下字段,我想禁用链接或显示警告。填写完字段后,用户将可以再次单击该按钮。
<form class="form-wrap mt-4">
<div class="btn-group" role="group" aria-label="Basic example">
<div class="select-wapper">
<%= select_tag :state, options_for_select([["Select a state",""]] + State.all.map { |c| [c.name, c.id] },selected: current_or_guest_user.search_state ), required: true, id: "state"%>
</div>
<div class="select-wapper">
<%= select_tag :city, options_for_select([["Select a City",""]] + City.all.map { |c| [c.name, c.id] }, selected: current_or_guest_user.search_city), required: true, :id => 'city' %>
</div>
<a href="/welcome/search" class="btn-form search-btn">Submit<i class="pe-7s-angle-right"></i></a>
</div>
</form>
答案 0 :(得分:0)
禁用具有属性onclick =“ return false”的链接
$('#city, #state').change(function() {
if($("option:selected").length == 2)
$('.search').attr('onclick', '')
})