Skip to content

Commit

Permalink
work on javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaltom committed Mar 9, 2012
1 parent 5a41447 commit 5764b05
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions app/views/search/_find_form.rhtml
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
<% content_for :ready_function do %>

$("#search_form").keyup(function() {

if ($("#search_form").val().length > 2) {
$.ajax({ url: "<%= url_for :controller => :search, :action => :searchresult %>",
cache: true,
data: {q: $("#search_form").val() },
beforeSend: function() {
$('#search-loader').show();
},
complete: function(){
$('#search-loader').hide();
},
success: function(html){
$("#search_result_container").html(html);
$('#msg').html("");
},
error: function(jqXHR, textStatus, errorThrown) {
$('#msg').html(textStatus + errorThrown);
},


});

} else {
$('#msg').html("Please enter more than 2 characters");
}

})

<% end -%>
<script type="text/javascript">

$(function() {

var last_search = "";
$("#search_form").keyup(function() {
if ($("#search_form").val() != last_search) {

if ($("#search_form").val().length > 2 ) {
$('#msg').html("");
last_search = $("#search_form").val();
$.ajax({ url: "<%= url_for :controller => :search, :action => :searchresult %>",
cache: true,
data: {q: $("#search_form").val() },
beforeSend: function() {
$('#search-loader').show();
},
complete: function(){
$('#search-loader').hide();
},
success: function(html){
$("#search_result_container").html(html);
$('#msg').html("");
},
error: function(jqXHR, textStatus, errorThrown) {
$('#msg').html(textStatus + errorThrown);
}
});

} else {
$('#msg').html("Please enter more than 2 characters");
}
}

})
});
</script>


<div class="box box-shadow grid_12 pkg-search-box">

<% form_tag( {:controller => 'search', :action => :searchresult}, :method => :get ) do %>
<%= text_field_tag 'q', @search_term, :size => 40, :id => "search_form" %>
<%= submit_tag _('Search'), :name => nil, :class => "search-go-button" %>
<% end -%>
<% form_tag( {:controller => 'search', :action => :searchresult}, :method => :get ) do %>
<%= text_field_tag 'q', @search_term, :size => 40, :id => "search_form", :autocomplete => "off" %>
<%= submit_tag _('Search'), :name => nil, :class => "search-go-button" %>
<% end -%>

</div>

Expand Down

0 comments on commit 5764b05

Please sign in to comment.