# Problem with disable\_with

**URL:** <https://www.ruby-forum.com/t/problem-with-disable-with/157239>\
**Category:** Rails\
**Created:** [January 8, 2009, 7:20pm UTC](https://www.ruby-forum.com/t/problem-with-disable-with/157239 "2009-01-08T19:20:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walter\_Lockhart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba8739/32.png) [@Walter\_Lockhart](https://www.ruby-forum.com/u/Walter_Lockhart)\
**Post date:** [January 8, 2009, 7:20pm UTC](https://www.ruby-forum.com/t/problem-with-disable-with/157239/1 "2009-01-08T19:20:16Z")

</div>

Hi Group,

I have a registration.html.erb page with the following JavaScript at  
the top which I use to validate form fields:

further down the page I have the form:

\<% form\_tag({:action =\> ‘sendregistration’}, {:name =\>  
“myForm”, :onSubmit =\> “return validate()”}) do -%\>

Project Name: **&nbsp;\*** \<%= text\_field 'email', 'projectname', :size =\> 30 %\> Project Type: **&nbsp;\*** \<%= collection\_select 'email', 'projecttype\_id', @projecttypes, :id, :name, { :include\_blank =\> true } %\> Region: **&nbsp;\*** \<%= collection\_select 'email', 'region\_id', @regions, :id, :name, { :include\_blank =\> true } %\>

etc.

\<%= submit\_tag “Send”, :class =\> “submit”, :id =\>  
“mysubmit”, :disable\_with =\> “Please wait…” %\>

\<% end -%\>

When I click ‘Send’ without the required fields the ‘Send’ button is  
disabled and the text is replaced with ‘Please wait…’ which is as I  
expected. It also performs the ‘validate’ JavaScript function and  
discovers that the required fields are not provided and displays a  
popup window with the text ‘You must fill in all of the required  
fields!’

When I click ‘Send’ with the required fields the ‘Send’ button is  
disabled and the text is replaced with ‘Please wait…’ which again is  
as I expected. However, the form does not Submit / Post, it just  
hangs.

What am I doing wrong? Would someone please help.

Thanks.

Regards

Walter

---

<div class="post-metadata">

**Author:** ![Walter\_Lockhart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba8739/32.png) [@Walter\_Lockhart](https://www.ruby-forum.com/u/Walter_Lockhart)\
**Post date:** [January 8, 2009, 8:26pm UTC](https://www.ruby-forum.com/t/problem-with-disable-with/157239/2 "2009-01-08T20:26:54Z")

</div>

You can always return false and inside the else block, add this  
javascript that will submit the form:  
document.forms[“myForm”].submit();

---

<div class="post-metadata">

**Author:** ![Walter\_Lockhart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba8739/32.png) [@Walter\_Lockhart](https://www.ruby-forum.com/u/Walter_Lockhart)\
**Post date:** [January 8, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/problem-with-disable-with/157239/3 "2009-01-08T21:30:29Z")

</div>

Hi Klaus,

thanks for your response. I tried this:

which I hope is what you were proposing in your response, but it still  
doesn’t Post. It just hangs.

Regards

Walter

---

<div class="post-metadata">

**Author:** ![Walter\_Lockhart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba8739/32.png) [@Walter\_Lockhart](https://www.ruby-forum.com/u/Walter_Lockhart)\
**Post date:** [January 8, 2009, 10:02pm UTC](https://www.ruby-forum.com/t/problem-with-disable-with/157239/4 "2009-01-08T22:02:16Z")

</div>

Hi Klaus,

thanks for your help. The following code now works:

Thanks again.

Regards

Walter

---

<div class="post-metadata">

**Author:** ![Walter\_Lockhart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba8739/32.png) [@Walter\_Lockhart](https://www.ruby-forum.com/u/Walter_Lockhart)\
**Post date:** [January 8, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/problem-with-disable-with/157239/5 "2009-01-08T21:39:54Z")

</div>

Hi Klaus,

now I’m really confused. When I remove the validation and use return  
true:

It posts, no problem.

Any ideas?

Regards

Walter
