Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twitter-bootstrap closing alert does not work

I can't get it to work. When I click the close button, nothing happens.

here's the code:

 <div class=" alert alert-error alert-block" style="width:200px" >
    <button class="close" data-dismiss="alert">&times;</button>
        <span>errors</span>            
    </div>

I've reproduced the issue on jsfiddler: http://jsfiddle.net/graphicsxp/7L7Nd/

EDIT

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "quoteWizard" }))
{
    <input type="hidden" id="ModelType" value="CarQuoteRequestViewModel" />


    ViewBag.ValidationSummaryClass = ViewData.ModelState.IsValid ? "validation-summary-valid" : "validation-summary-errors";

    <div class="@ViewBag.ValidationSummaryClass alert alert-error in fade" data-valmsg-summary="true">
    <button class="close" data-dismiss="alert">&times;</button>
        <span>Before you can continue, please make sure you have completed the mandatory fields
            highlighted below.</span>
        <ul style="display: none" />
    </div>



    @RenderSection("QuoteSection")

    <div class="ui-formwizard-nav">
        <input id="back" value="@Resource.Global.Previous" type="reset" class="btn btn-primary" />
        <input id="next" value="@Resource.Global.Next" class="btn btn-primary" type="submit" />
    </div>
}
like image 209
Sam Avatar asked Mar 06 '13 11:03

Sam


3 Answers

It appears that the order in which you include the Javascript sources is important. First load jQuery, then the Bootstrap Javascript.

E.g. This fails:

<script src="/js/vendor/bootstrap.min.js"></script>
<script src="/js/vendor/jquery-1.9.1.min.js"></script>

and this works:

<script src="/js/vendor/jquery-1.9.1.min.js"></script>
<script src="/js/vendor/bootstrap.min.js"></script>

You'll also see this in the example templates. From the Hero template:

[...]
<script src="/../assets/js/jquery.js"></script>
<script src="/../assets/js/bootstrap-transition.js"></script>
<script src="/../assets/js/bootstrap-alert.js"></script>
[...]
like image 153
gertvdijk Avatar answered Nov 07 '22 02:11

gertvdijk


I've sorted it out.

Instead of using a button, I'm now using a span, so the form doesn't get submitted:

        <span class="close" data-dismiss="alert">&times;</span>

thanks for your help

like image 31
Sam Avatar answered Nov 07 '22 02:11

Sam


Edited from Shail that just changing from alert-error to alert-danger

<div class=" alert alert-danger alert-block" style="width:200px">
     <button class="close" data-dismiss="alert">&times;</button>
     <span>
             Before you can continuelds
             highlighted below.
     </span>
</div>

Jsfiddle Demo

like image 1
Juna serbaserbi Avatar answered Nov 07 '22 02:11

Juna serbaserbi