Jim Jeffers
2005-Oct-06 20:04 UTC
Using AJAX to Disable and Re-enable a form field or button.
I was wondering if there is an Ajax helper like:
Element.show(''search-indicator'')
That will allow me to enable or disable a field or button on a form
so that the user cannot accidentally resubmit the form as it''s being
processed.
- Jim
Lee Marlow
2005-Oct-06 21:09 UTC
Re: Using AJAX to Disable and Re-enable a form field or button.
No AJAX required, just a little javascript.
The snippet below works for me. "commit" is just the default name for
the button generated by <%= submit_tag %>
<%= start_form_tag({:action => ''do_something''},
{:onsubmit =>
"this.commit.disabled=true;"}) %>
<%= submit_tag ''Do Something'' %>
<%= end_form_tag %>
On 10/6/05, Jim Jeffers
<rails-u78NUfcIof50Y1uG8So6J1aTQe2KTcn/@public.gmane.org>
wrote:> I was wondering if there is an Ajax helper like:
> Element.show(''search-indicator'')
>
> That will allow me to enable or disable a field or button on a form
> so that the user cannot accidentally resubmit the form as it''s
being
> processed.
>
> - Jim
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Julian ''Julik'' Tarkhanov
2005-Oct-06 21:49 UTC
Re: Using AJAX to Disable and Re-enable a form field or button.
On 6-okt-2005, at 22:04, Jim Jeffers wrote:> I was wondering if there is an Ajax helper like: > Element.show(''search-indicator'') > > That will allow me to enable or disable a field or button on a form > so that the user cannot accidentally resubmit the form as it''s > being processed.Not as such, but you can write one yourself. For instance you can make an addition to form_remote that will disable any inputs with "type=submit" and reenable them as soon as the form is loaded again. Besides you have an option of :loading in all remote helpers - there you can put an AJAX call to be executed before the stuff starts to load, and then you get :loaded which allows you to reenable the inputs. As far as disbaling inputs goes - you can just try and whip up one yourself (as we finally have at Least Some Feasible And Understandable Documentation for prototype) -- Julian "Julik" Tarkhanov