Question

I did a jquery to block the search button until my textfields has text but is not working.

When I write values into textfields the search button is still block and not unblock like this:

http://jsfiddle.net/qKG5F/1627/

Here is the controller:

class PolicyController < ApplicationController
   def index
     @policies = Policy.find(:all,:conditions=>['date BETWEEN ? AND ?',params[cam],params[:cam2] ])
   end
end

Here is the view

<script type="text/javascript">
(function() {
  $('form > input').keyup(function() {

    var empty = false;
    $('form > input').each(function() {
        if ($(this).val() == '') {
            empty = true;
        }
    });

    if (empty) {
        $('#search').attr('disabled', 'disabled');
    } else {
        $('#search').removeAttr('disabled');
    }
});
})()
</script>

<% form_tag :controller=>"policy",:action=>"index" do %>
   From: <%= calendar_date_select_tag  "date1", params[:date1]  %>

   To:   <%= calendar_date_select_tag  "date2",params[:date2] %>   
   <input type="submit" id="search" value="GO" />
<% end %>

<% @policies.each  do |p|%>
   <%= p.date_ini %>
<% end %>   

I tried:

<%= javascript_include_tag :defaults %>

And also I have the prototype 1.6.0.3 file in /public/javascripts/prototype.js

Also I don't have any errors in log

Somebody told me about convert jquery code to prototype code.

Please somebody can help me with this?

Was it helpful?

Solution

To include the Prototype and Scriptaculous javascript libraries in your application, pass :defaults as the source. When using :defaults, if an application.js file exists in your public javascripts directory, it will be included as well.

  javascript_include_tag :defaults # =>
    <script type="text/javascript" src="/javascripts/prototype.js"></script>
    <script type="text/javascript" src="/javascripts/effects.js"></script>
    ...
    <script type="text/javascript" src="/javascripts/application.js"></script>

If you have issues with :defaults reference,

Try to use :all option.

javascript_include_tag :all # =>
    <script type="text/javascript" src="/javascripts/prototype.js"></script>
    <script type="text/javascript" src="/javascripts/effects.js"></script>
    ...
    <script type="text/javascript" src="/javascripts/application.js"></script>
    <script type="text/javascript" src="/javascripts/shop.js"></script>
    <script type="text/javascript" src="/javascripts/checkout.js"></script>

Refer: http://apidock.com/rails/v2.3.2/ActionView/Helpers/AssetTagHelper/javascript_include_tag

OR explicitly refer the prototype.js file,

<%= javascript_include_tag "prototype" %>

Hope it helps :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top