Twitter bootstrap warning hides during initialization

I am using twitter bootstrap for my warnings and I want a warning to appear when there was an error on the inputs. I can hide it during initialization and show it after an error occurs. But after that the warning disappears again. is there any way to ensure that the warning remains there until the correct input is specified

<div class="span4"> <div class="alert alert-error fade in" id = "user_name_exist" > <button type="button" class="close">×</button> <h4 class="alert-heading">Username error!</h4> The username entered is used by another user. Please choose another one! </div> </div> 

Can anybody help me?

+6
source share
3 answers

For what it's worth, I'm not a fan of editing downloaded packages. I have the same thing at my end, but I just deleted the data-dismiss="alert" portion of the close button. Then, basically the same code as Nintin is used to hide the warning.

HTML code

 <div id="AddAlert" class="alert alert-block" style="display:none;"> <button type="button" class="close">&times;</button> <h4 id="AddAlertH4">Error</h4> <div id="AddAlertMessage">My error message goes here.</div> </div> 

Js code

 $(".close").click(function(){ $("#AddAlert").hide(); }); 

I also dynamically populate my error messages using PHP, but I did not draw it here, as it is not part of the question.

+5
source

You need to remove the line from bootstrap-alert.js file

 function removeElement() { $parent .trigger('closed') .remove() } 

Delete .remove () and save the js file

than add javascript to your code to manually close ex

  $(".close").click(function(){ $("#myalert").hide(); }); 
0
source

This is an old question, but it worked for me (from another answer on stackoverflow, but I can no longer find a link to this answer). Hope this helps someone.

 $('.alert .close').on("click", function(e) { e.stopPropagation(); e.preventDefault(); $(this).parent().hide(); }); 
0
source

Source: https://habr.com/ru/post/919216/


All Articles