我有5个搜索过滤器,一个是text-field-tag,两个是引导多个选择下拉菜单,另外两个是使用datetimepicker实现的从日期到日期。我需要一个重置按钮来将值重置为默认值(页面加载期间填充的值)。有人可以帮我吗
我有一个在ruby on rails中实现的html,controller和js文件。
<div class="row">
<%= form_tag({controller: "fraud_search", action: "search"}, method: "post", style: "margin-bottom: 20px;", id: "fraud_search_crit_form") do %>
<div class="row" style="padding:10px;">
<div class="col-md-2">
<label for="fraud_order_id">Order ID</label><br>
<div class="input-group">
<%= text_field_tag :fraud_order_id, params[:fraud_order_id], class: 'form-control' %>
<span class="input-group-addon">
<button type="button" class="search_reset" id="fraud_order_id_reset" onclick="resetFraudform(this.id)"><span class="ss-icon ss-delete ss-black-tie-bold"></span></button></span>
</div>
</div>
<div class="col-md-2">
<%= label_tag :fraud_status, "Status" %>
<div class="form-group" id="fraud_status">
<%= select_tag "fraud_status[]",
options_for_select(@fraud_order_statuses.map {|status| [status[:name], status[:id]]}, :selected => @selected_fraud_status),
{id: 'fraud_status', class: 'form-control selectpicker', 'multiple' => 'true', 'data-actions-box' => (@fraud_order_statuses.map {|status| [status[:name], status[:id]]}.size > 1), 'data-selected-text-format' => 'count > 2', 'data-count-selected-text' => 'All'} %>
</div>
</div>
<div class="col-md-2">
<%= label_tag :stores, "Stores" %>
<div class="form-group" id="fraud_stores">
<% stores = @store_list.to_a %>
<%= select_tag "fraud_store_ids[]",
options_for_select(stores, :selected => @selected_store),
{id: 'fraudStoreList', class: 'form-control selectpicker', 'multiple' => 'true', 'data-actions-box' => (stores.size > 1), 'data-selected-text-format' => 'count > 3'} %>
</div>
</div>
<div class='col-md-2'>
<%= label_tag :fraudStartDate, "From Date (" + Time.now.in_time_zone(@timezone).strftime('%Z') + ")" %>
<br>
<div class="form-group">
<div class='input-group date' id='fraudStartDate'>
<%= text_field_tag :fraud_start_date, '', class: 'form-control' %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class='col-md-2'>
<%= label_tag :fraudEndDate, "To Date (" + Time.now.in_time_zone(@timezone).strftime('%Z') + ")" %>
<br>
<div class="form-group">
<div class='input-group date' id='fraudEndDate'>
<%= text_field_tag :fraud_end_date, '', class: 'form-control' %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-md-1">
<%= hidden_field_tag :fraud_show_results, "true" %>
<%= hidden_field_tag :timezone_fraud, @moment_timezone %>
<%= hidden_field_tag :fraud_start_date_utc, params[:fraud_start_date_utc] %>
<%= hidden_field_tag :fraud_end_date_utc, params[:fraud_end_date_utc] %>
<%= hidden_field_tag :reset_start_date, params[:reset_start_date] %>
<%= hidden_field_tag :reset_end_date, params[:reset_end_date] %>
<%= hidden_field_tag :page, params[:page] %>
<%= hidden_field_tag :per_page, params[:per_page] %>
<%= label_tag "" %>
<div class="form-group">
<%= submit_tag("Search", :id => "fraud_show_results_submit", :class => "btn btn-primary", :name => "fraud_show_results_submit", :remote => true) %>
</div>
</div>
<input type="button" id="reset-form" value="Reset" />
</div>
<% end %>
$('#reset-form').on('click', function()
{
$("#fraud_search_crit_form")[0].reset();
});
我需要将值设置为默认值。但它清空了字段
答案 0 :(得分:0)
在表单内部添加重置按钮。
<button type="reset" value="Reset"> Reset Form </button>