# Disabling "Submit" button in form\_remote\_tag in dialog box

**URL:** <https://www.ruby-forum.com/t/disabling-submit-button-in-form-remote-tag-in-dialog-box/181804>\
**Category:** Rails\
**Created:** [January 18, 2010, 3:42pm UTC](https://www.ruby-forum.com/t/disabling-submit-button-in-form-remote-tag-in-dialog-box/181804 "2010-01-18T15:42:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 18, 2010, 3:42pm UTC](https://www.ruby-forum.com/t/disabling-submit-button-in-form-remote-tag-in-dialog-box/181804/1 "2010-01-18T15:42:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [January 18, 2010, 4:42pm UTC](https://www.ruby-forum.com/t/disabling-submit-button-in-form-remote-tag-in-dialog-box/181804/2 "2010-01-18T16:42:35Z")

</div>

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
