I need to auto fade the flash messages in ruby on rails.
My message code is:
<%= simple_form_for(@dashboard_user) do |f| %>
<% if @dashboard_user.errors.any? %>
<ul class="alert alert-danger">
<% for message_error in @dashboard_user.errors.full_messages %>
<li>
<%= message_error %>
</li>
<% end %>
</ul>
<% end %>
How i auto fade these messages?
This should work for you. You can specify the time span within the brackets. Add this to your Javascript. this is common for all:
$(".alert" ).fadeOut(3000);
For alert success:
$(".alert-success" ).fadeOut(3000);
For alert danger:
$(".alert-danger" ).fadeOut(3000);
This one will work with Turbolinks-3.
$(document).on('page:change', function(){
$(".alert").delay(2000).slideUp(500, function(){
$(".alert").alert('close');
});
});
Turbolinks 5:
$(document).on('turbolinks:load', function(){
$(".alert").delay(2000).slideUp(500, function(){
$(".alert").alert('close');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With