Disabling "Submit" button in form_remote_tag in dialog box

Hello all,

I have a jQuery dialog that renders a search form using
“form_remote_tag”

  • _searchDialog.html.erb -
Please type IRB number or part of a number
If search does not retrieve desired results, please refine search.
<% form_remote_tag :update => "searchResults", :url => {:controller => 'irbs', :action => 'search'}, :position => "top", :complete => "clearForm()" do -%> <%= text_field_tag :search, params[:search], :size => 30 %> <%= submit_tag 'Search', :class => 'searchButton' %> <% end -%> IRB Number:

I can get the search results to display but my problem is if the user
clicks on the submit button twice the search will continue to add the
results to the “searchResults” div.

Then only answer is to either disable the submit button or somehow
disable the search feature.
I’ve tried using “:disable_with” to disable the submit button and it
didn’t work.

Thank you for any help on this.

JohnM

Well, I answered this one on my own.

In my “applications.js” file, I have a function that opened the jquery
dialog box.

  • application.js -
    function addIrb(id){
    jQuery.ui.dialog.defaults.bgiframe = true;
    jQuery(function(){
    jQuery(’#add’).dialog({
    title: ‘Search IRB Records’,
    position: [200,50],
    width:‘auto’,
    resizable:false,
    buttons: {
    “Close”:function() {
    var value = “”;
    jQuery(‘input[type=submit]’).removeAttr(‘disabled’);
    jQuery(‘input#search’).val(value);
    jQuery(’.searchResults’).empty();
    jQuery(this).dialog(‘destroy’);
    }
    },
    error: function(){
    alert(‘Error’);
    },
    success: function(){
    alert(‘Success’);
    }
    }); // end jQuery dialog
    });
    } // end function

and in the dialog box I render a form using “form_remote_tag”.

  • _searchDialog.html.erb -

<% form_remote_tag :update => “searchResults”,
:url => {:controller => ‘irbs’, :action => ‘search’},
:html => { :name => “searchForm” },
:position => “top”,
:complete => “clearForm()” do -%>

<%= text_field_tag :search, params[:search], :size => 30 %>
<%= submit_tag ‘Search’, :class => ‘searchButton’ %>

<% end -%>

IRB Number:

When the search is performed, I disable the button by calling
clearForm() function on complete.

  • clearForm() in application.js -
    function clearForm(id){
    new Effect.SlideDown(‘searchResults’);
    jQuery(function(){
    jQuery(‘input[type=submit]’, this).attr(‘disabled’, ‘disabled’);
    })
    }

Then when the dialog is closed, ( “Close”:function()… )
I remove the “disabled” attribute. This way when you open the dialog box
again, the button is enabled.

Hope that helps someone with the same problem.

JohnM

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs