Permalink
Browse files

Store current search query in search field

  • Loading branch information...
1 parent 73b7b65 commit e2ec5640b0e4cc84dd62499b723e321398e7197e @rmg committed Mar 5, 2012
@@ -48,9 +48,8 @@ $(function () {
// things like backspace and delete
events = (live ? "keydown change search" : "change search"),
timer = null,
- minLength = $(input_id).data("min-length") || 3,
- current = $(input_id).val();
- $grid.parent().on(events, input_id, function (e) {
+ minLength = $(input_id).data("min-length") || 3;
+ $grid.on(events, input_id, function (e) {
var is_manual = (e.type == 'search' ||
e.type == 'change' ||
(e.type == 'keydown' && e.which == '13')
@@ -63,6 +62,7 @@ $(function () {
clearTimeout(timer);
timer = setTimeout(function () {
var $input = $(input_id),
+ current = $input.data("current"),
value = $input.val(),
length = value.length,
url = base_url + "?",
@@ -79,7 +79,7 @@ $(function () {
// Move the cursor back to where it was,
// less surprising that way.
// EXCEPT FOR IE, that is
- current = $(input_id).setCursor(pos).val();
+ $(input_id).setCursor(pos);
});
} else {
window.location = url;
@@ -19,6 +19,7 @@ class Definition
:searcher => false,
:needs_searcher => false,
:live_search => true,
+ :current_search => nil,
:listeners => {},
:listener_handler => nil,
:default_col => 0,
@@ -107,6 +108,7 @@ def initialize(cols_or_opts, collection = nil, controller = nil, opts = {})
@options[:listeners] = {}
end
end
+ @options[:current_search] ||= param(:q)
if (@collection.respond_to?(:where) or
(@options[:use_search_method] and @collection.respond_to?(:search)))
if param(:q) and @options[:searchable]
@@ -45,11 +45,14 @@ def magic_grid(collection = nil, cols = nil, opts = {}, &block)
if grid.options[:needs_searcher]
thead << content_tag('tr') do
content_tag 'td', :class => 'searcher', :colspan => grid.columns.count do
+ searcher_data = {
+ :min_length => grid.options[:min_search_length],
+ :current => grid.options[:current_search] || "",
+ }
searcher = label_tag(grid.options[:searcher].to_sym, 'Search: ')
searcher << search_field_tag(grid.options[:searcher].to_sym,
grid.param(:q),
- :data => {:min_length =>
- grid.options[:min_search_length]})
+ :data => searcher_data)
unless has_spinner
has_spinner = true
searcher << spinner
@@ -23,6 +23,7 @@
}
],
:searchable => [:body, 'users.name'],
+ :use_search_method => false,
:min_search_length => 2,
:per_page => 5,
:listeners => {

0 comments on commit e2ec564

Please sign in to comment.