提交和页面重新加载后,我的表单复选框如何保持其状态?
我有一个包含复选框的表单,该表单用于过滤索引页面上的记录,一旦提交表单并重新加载页面后,如何使表单中的复选框保持其选中状态?
I have a form consisting of checkboxes which is filtering records on an index page, how can I make the checkboxes in the form keep their checked state once the form is submitted and the page is reloaded?
我已经在使用jQuery-UI使复选框看起来更好.我对任何一种编程都非常陌生,并且对javascript的了解较少.
I'm already using jQuery-UI to make the checkboxes look better. Im super new to any kind of programming and having less luck with javascript.
index.html.erb
<script>
$(function() {
$(".areas").buttonset();
});
$(function() {
$( "button, input:submit, a", ".filter_form_button" ).button();
$( "a", ".form_filter_button" ).click(function() { return false; });
});
</script>
<div class="filter_options_container">
<%= form_tag '', :method => :get, :id => 'filter_form' do %>
<fieldset class="filter_form_fieldset areas">
<% Area.all.each do |a| %>
<p class="area_check"><%= check_box_tag 'areas[]', a.id, false, :id => "area-#{a.id}" %>
<label for="area-<%= a.id %>"><p1><%= a.name %></p1></label></p>
<% end %>
</fieldset>
<div class="filter_form_button">
<p2><input type="submit" value="Filter"/></p2>
</div>
<% end %>
</div>
对此有任何帮助,深表感谢!
Any help with this is much appreciated!
我发现了这个jQuery插件,可以在您离开或返回时保持填写表格的状态.似乎工作得很好. dumbFormState
I found this jQuery plugin that keeps the form filled in when you leave and come back. Seems to work really well. dumbFormState