I''ve got a remote form (that''s actually just a submit button), and I''ve got it working to the point where it makes all the changes necessary. Now for some cosmetics...when the user presses the button and the request starts, I want the button to become inactive and the text changed to "Saving..." Then when it''s all done, I''d like to display "Updated" next to the button. How can I do this?
Ajax is pretty slick once you figure out what you need to do...for
anyone interested, here''s how I did what I wanted.
<%= form_remote_tag(:url => { :action =>
"#{@subscribe_action}" },
:update => "list_subscribe_div", :loading =>
"$(''subscribe_button'').value=''Saving...'';$(''subscribe_button'').disabled=''true'';Element.hide(''subscribe_updated'')",
:complete => "Element.show(''subscribe_updated'')")
%>
<%= submit_tag("#{@subscribe_label}", :id =>
"subscribe_button") %>
<span id="subscribe_updated"
style="display:none">Updated</span>
<%= end_form_tag %>
The action is either ajax_subscribe or ajax_unsubscribe, and they
perform all the work then render the partial.
On 8/26/05, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''ve got a remote form (that''s actually just a submit
button), and
> I''ve got it working to the point where it makes all the changes
> necessary. Now for some cosmetics...when the user presses the button
> and the request starts, I want the button to become inactive and the
> text changed to "Saving..." Then when it''s all done,
I''d like to
> display "Updated" next to the button. How can I do this?
>
You can use the following example:
<%= observe_field("search",
:update => :results,
:url => { :action => :search},
:before => "CODE TO DISABLE BUTTON",
:after => "CODE TO EXECUTE AFTER",
:loading =>
"Element.show(''search-indicator'')",
:complete =>
"Element.hide(''search-indicator'')") %>
Enjoy!
Josh
On 8/26/05, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''ve got a remote form (that''s actually just a submit
button), and
> I''ve got it working to the point where it makes all the changes
> necessary. Now for some cosmetics...when the user presses the button
> and the request starts, I want the button to become inactive and the
> text changed to "Saving..." Then when it''s all done,
I''d like to
> display "Updated" next to the button. How can I do this?
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
On 8/26/05, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve got a remote form (that''s actually just a submit button), and > I''ve got it working to the point where it makes all the changes > necessary. Now for some cosmetics...when the user presses the button > and the request starts, I want the button to become inactive and the > text changed to "Saving..." Then when it''s all done, I''d like to > display "Updated" next to the button. How can I do this?You would have to create javascript functions that you would reference in :loading and :complete arguments of form_remote_tag. ie form_remote_tag(:loading => ''loading()'', :complete => ''updateComplete()'') javascript: function loading() { form.submitbutton.value = ''Saving...'' form.submitbutton.disabled = true } function updateComplete() { form.submitbutton.value = ''Submit'' form.submitbutton.disabled = false new Effect.Appear(''updateDiv''); // updateDiv would contain your "Updated" text. } I hope this helps -- Nick Hall Alexssa Enterprises p: 262.338.3742 m: 262.208.6271 Never lose your data! Try it free at www.neverlosedata.com.
On 8/26/05, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve got a remote form (that''s actually just a submit button), and > I''ve got it working to the point where it makes all the changes > necessary. Now for some cosmetics...when the user presses the button > and the request starts, I want the button to become inactive and the > text changed to "Saving..." Then when it''s all done, I''d like to > display "Updated" next to the button. How can I do this?Have a look at :loading, :complete, and other options from link_to_remote http://api.rubyonrails.com/classes/ActionView/Helpers/JavaScriptHelper.html#M000395 I''d do something like this <%form_remote_tag( :update => ''idToUpdate'', :url => {:action => ''remote_action''}, :loading => "Element.show(''savingMsgDiv'');", :complete => "Element.hide(''updatedMsgDiv'');" ) %> -- Chris Martin Web Developer Open Source & Web Standards Advocate http://www.chriscodes.com/
On 8/26/05, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ajax is pretty slick once you figure out what you need to do...for > anyone interested, here''s how I did what I wanted.Not sure why, but gmail wasn''t showing me any replies to this, until after I replied, then I saw that you replied to yourself, but it was still listed after my reply... ? Good idea changing the text of the button, but you may consider just removing it all together, and displaying a saving message. It''s a good way to prevent double submissions. As you''ve found, Rails makes it easy enough. -- Chris Martin Web Developer Open Source & Web Standards Advocate http://www.chriscodes.com/