DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
224 stars 79 forks source link

ValidationSummary ExcludePropertyErrors #368

Closed speshulk926 closed 9 years ago

speshulk926 commented 9 years ago

I seem to be having an issue when I set ExcludePropertyErrors, it still shows the ValidationSummary border, but nothing inside. So it's "working", but still displaying and I'm not sure why. Since I could not find anyone else having this issue, I'm assuming it's something I'm doing. Here's some relevant code to see what I may be doing wrong.

@using (var f = Html.Bootstrap().Begin(new Form().Type(FormType.Horizontal).LabelWidthSm(2)))
{
    @Html.Bootstrap().ValidationSummary().ExcludePropertyErrors()
    @Html.AntiForgeryToken()

    @f.FormGroup().TextBoxFor(m => m.Username).AutoFocus(true).PrependIcon(new Icon("glyphicon glyphicon-user"))
    @f.FormGroup().TextBoxFor(m => m.Password).PrependIcon(new Icon("glyphicon glyphicon-lock"))
    @f.FormGroup().ActionLink("Reset Password", "ResetPassword") 
    @f.FormGroup().CustomControls(Html.Bootstrap().SubmitButton().Text("Login").LoadingText("Logging in").Style(ButtonStyle.Primary))

}

Before submit: image image

After submit: image image

speshulk926 commented 9 years ago

Well, I figured out why this happened. The link on documentation for the scripts (https://www.twitterbootstrapmvc.com/Documentation) links to (https://www.twitterbootstrapmvc.com/Scripts/TwitterBootstrapMvcJs-3.0.4.js). At the very top it shows: $('.bmvc-3-validation-summary').addClass('alert alert-danger').find('.close').show();

When I look at the Nuget package version, it shows: $('.bmvc-3-validation-summary').has('li').addClass('alert alert-danger').find('.close').show();

I figured the NugetPackage one was maybe more-updated, so I linked that one instead and it kills all my Javascript on the page. I can't see any discernible reason why.

However, when I copy/paste that one line into my existing "working" js file, everything works as intended.

DmitryEfimenko commented 9 years ago

Sorry could not reply earlier and glad you figured this out. Yeah, it's always safer to have latest from nuget.

Though the fact that this script kills all your JavaScript is disturbing. Is there any JavaScript errors in the browser console?

speshulk926 commented 9 years ago

No, but I'll post my bundle config and some more later to see if I may be doing something incorrect.

Thank you for your response.

speshulk926 commented 9 years ago

I tried a few things and it doesn't appear javascript is dead on the page, but my javascript validation is.

I added this and I get the alert:

< button onclick="alert('hey there'); return false;" >Test< /button >

Here's my bundle config.

public class BundleConfig
{
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Content/js/jquery-{version}.js"));
        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Content/js/jquery.validate*"));
        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Content/js/modernizr-*"));
        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Content/js/bootstrap.js",
                  "~/Content/js/respond.js",
                  "~/Content/js/TwitterBootstrapMvcJs.js"));
        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/css/bootstrap.css",
                  "~/Content/css/site.css"));
        // Set EnableOptimizations to false for debugging. For more information,
        // visit http://go.microsoft.com/fwlink/?LinkId=301862
        BundleTable.EnableOptimizations = false;
    }
}

Here's my directory structure to show where it is located. The highlighted one is the Nuget package. The one with a version is from the site. image

Here's the HTML output showing what order it loaded everything in: image

Here's the HTML output of one of the form groups: image

speshulk926 commented 9 years ago

Just messing around I moved the reference to TwitterBootstrapMvcJs.js to the jqueryval bundle and it started working. I'm not seeing any other issues after that. I'm guessing it's just an ordering and it wanted to be after the jquery.validate.unobtrusive.js.

DmitryEfimenko commented 9 years ago

Something that might be relevant from the screenshot you showed: you had TwitterBootstrapMvcJs.js in the ~/bundles/bootstrap bundle. However, on the page you referenced both, the ~/bundles/bootstrap and TwitterBootstrapMvcJs.js file, which means this file was referenced twice in the code. Just wanted to point this out.