开发者

fadeout in ruby (flash:notice) not working properly

开发者 https://www.devze.com 2023-01-06 16:53 出处:网络
I have a simple email entry that is supposed to flash a notice \"Email cannot be blank or invalid\" when the user pushes the submit button and the email is blank or invalid. I\'ve managed to get that

I have a simple email entry that is supposed to flash a notice "Email cannot be blank or invalid" when the user pushes the submit button and the email is blank or invalid. I've managed to get that working so the notice pops up just on top of the email entry form. But what I want is the error message to be directly over the email entry form and then fade out. I've been looking up different fadeout snippets and everything seems super simple - so what I am missing? Appreciate any help.

this is in the application helper:

def show_flash_message(options={})
html = content_tag(:div, flash.collect{ |key,msg| content_tag(:div, msg, :class => key) }, :id => 'flas开发者_Python百科h-message')
if options.key?(:fade)
html << content_tag(:script, "setTimeout(\"new Effect.Fade('flash-message');\",#{options[:fade]*1000})", :type => 'text/javascript')
end
html

end

this is in the layout: <%= javascript_include_tag :all %>

This is in the view: <%- flash.each do |flash_type, message| -%> <%= content_tag :div, message, :class => "flash #{flash_type}" %> <% content_tag :script, :type => "text/javascript" do %> setTimeout("$$('div.flash').each(function(flash){ flash.hide();})", 1000); <% end %> <%- end -%>

<div class="inputs" style="margin-left:30px">
<%= f.text_field :email, :value => 'Please enter your email.', :onfocus => "if(this.value==this.defaultValue) this.value=''; this.style.color = '#333333'", :onblur => "if(this.value=='') this.value=this.defaultValue;this.style.color = '#aaaaaa'"%> 


It looks like you're using Prototype from your $$ action there. You should checkout the Scriptaculous fade effect:

http://wiki.github.com/madrobby/scriptaculous/effect-fade

0

精彩评论

暂无评论...
验证码 换一张
取 消