Menu icon Foundation
Alert boxes not closing

I am writing the alert box into HTML with JQuery.
The first time it is written into the HMLT, it doesn't close when I click on the "x".
When I re-write the same form (with JQuery again), and trigger the alert, it works again.

There is nothing written to the console to report any errors/logs/anything.

I'm puzzled. Some help would be greatly appreciated.

PS: I'm working with Ruby on Rails

var error_msg = "";
var obj_name = "<%=j @object.class.name.underscore %>";
var obj_name_plural = "<%=j @object.class.name.underscore.pluralize %>";
var model_name = "<%=j @object.class.name.underscore.gsub(/_/, ' ').titleize %>";
  
<% if @object.errors.messages.empty? %>
  $(".error[data-error_notice]").each ( function (index) {
    if ( $(this).data('error_notice') == obj_name ) {
      $(this).remove();
    }
  });
  
  error_msg += "<div data-alert class=\"alert-box success round\">" +
                model_name +" Successfuly Created/Updated" +
                "<a href=\"#\" class=\"close\">&times;</a>" +
                "</div>";
  $("#"+ obj_name + "_flash_notice").html(error_msg);

<% else %>
  $(".error[data-error_notice]").each ( function (index) { 
    if ( $(this).data('error_notice') == obj_name ) {
      $(this).remove();
    }
  });

  error_msg += "<div data-alert class=\"alert-box alert round\">" +
                "Errors in Creating/Updating "+ model_name +
                "<a href=\"#\" class=\"close\">&times;</a>" +
                "</div>";

  <% @object.errors.messages.each do |name, msg| %>

    var msgs = "| ";
    <% msg.each do |m| %>
      msgs += "<%= m %>" + " | ";
    <% end %>
    var error = "<small class=\"error\" data-error_notice=\""+ obj_name +"\" >"+ msgs +"</small>";
    $("#"+ obj_name + "_" + "<%=j name.to_s %>").after(error);

  <% end %>
  $("#"+ obj_name + "_" + "flash_notice").html(error_msg);
<% end %>
            

         

alert-boxdata-alertclosing alert boxjqueryruby on railsrails

I am writing the alert box into HTML with JQuery.
The first time it is written into the HMLT, it doesn't close when I click on the "x".
When I re-write the same form (with JQuery again), and trigger the alert, it works again.

There is nothing written to the console to report any errors/logs/anything.

I'm puzzled. Some help would be greatly appreciated.

PS: I'm working with Ruby on Rails

var error_msg = "";
var obj_name = "<%=j @object.class.name.underscore %>";
var obj_name_plural = "<%=j @object.class.name.underscore.pluralize %>";
var model_name = "<%=j @object.class.name.underscore.gsub(/_/, ' ').titleize %>";
  
<% if @object.errors.messages.empty? %>
  $(".error[data-error_notice]").each ( function (index) {
    if ( $(this).data('error_notice') == obj_name ) {
      $(this).remove();
    }
  });
  
  error_msg += "<div data-alert class=\"alert-box success round\">" +
                model_name +" Successfuly Created/Updated" +
                "<a href=\"#\" class=\"close\">&times;</a>" +
                "</div>";
  $("#"+ obj_name + "_flash_notice").html(error_msg);

<% else %>
  $(".error[data-error_notice]").each ( function (index) { 
    if ( $(this).data('error_notice') == obj_name ) {
      $(this).remove();
    }
  });

  error_msg += "<div data-alert class=\"alert-box alert round\">" +
                "Errors in Creating/Updating "+ model_name +
                "<a href=\"#\" class=\"close\">&times;</a>" +
                "</div>";

  <% @object.errors.messages.each do |name, msg| %>

    var msgs = "| ";
    <% msg.each do |m| %>
      msgs += "<%= m %>" + " | ";
    <% end %>
    var error = "<small class=\"error\" data-error_notice=\""+ obj_name +"\" >"+ msgs +"</small>";
    $("#"+ obj_name + "_" + "<%=j name.to_s %>").after(error);

  <% end %>
  $("#"+ obj_name + "_" + "flash_notice").html(error_msg);
<% end %>
            

         
Minghua Zhao about 4 years ago

I just realized I put Framework as "Email".... should have been "Sites".... Is there a way to edit? :(