Hi everyone, I''d like to display a text in a div (an error message returned from an ajax form) for 2 seconds and then delete the div content. I do not want the div itself to fade out using scriptacolous - I want the content itself overwritten with an empty string. Is there a way of doing that in rails? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The best way of doing this is in Javascript. Scriptaculous is purely an
effects framework and has in and of itself nothing to do with Rails. If you
want to fade out/slide out, etc, then you can add such an effect later.
For just deleting the error div after 2 seconds, you''ll need to use
this
Javascript (using Prorotype):
setTimeout(2000, deleteDiv(''div_id''));
function deleteDiv(div) {
// Effect call can go here
Element.remove(div);
}
Where this goes of course depends on how the error div is displayed. If this
is a full page refresh, then a simple <script> tag after the div will
work.
Jason
On 4/18/07, Ehud Rosenberg
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Hi everyone,
> I''d like to display a text in a div (an error message returned
from an
> ajax
> form) for 2 seconds and then delete the div content.
> I do not want the div itself to fade out using scriptacolous - I want
> the content itself overwritten with an empty string.
>
> Is there a way of doing that in rails?
>
> Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Ehud Rosenberg wrote:> Hi everyone, > I''d like to display a text in a div (an error message returned from an > ajax > form) for 2 seconds and then delete the div content. > I do not want the div itself to fade out using scriptacolous - I want > the content itself overwritten with an empty string. > > Is there a way of doing that in rails? > > Thanks!RJS can contain raw JavaScript, so I''d make the result of the Ajax call a bit of RJS rather than HTML. The RJS can set the div contents to message text, then add a timeout function as above to replac it in 2s with "". A. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can also achieve this with RJS / Rails Helpers:
if the error message is set thorugh an AJAX response, you would do
something like in the rjs partial you render for the response:
page.replace_html :div_id "Your erro message here"
page.delay(2) do
page.replace_html :div_id, ""
end
if it''s a complete page refresh:
<div id="div_id"><%= @error_msg</div>
<script>
update_page do |page|
page.delay(2) do
page.replace_html :div_id, ""
end
end
</script>
On 19 Apr., 15:19, Alan Francis
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Ehud Rosenberg wrote:
> > Hi everyone,
> > I''d like to display a text in a div (an error message
returned from an
> > ajax
> > form) for 2 seconds and then delete the div content.
> > I do not want the div itself to fade out using scriptacolous - I want
> > the content itself overwritten with an empty string.
>
> > Is there a way of doing that in rails?
>
> > Thanks!
>
> RJS can contain raw JavaScript, so I''d make the result of the Ajax
call
> a bit of RJS rather than HTML. The RJS can set the div contents to
> message text, then add a timeout function as above to replac it in 2s
> with "".
>
> A.
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---