DmitryEfimenko / TwitterBootstrapMvc

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

ValidationSummary displays inconsistent behavior between client and server validation #74

Closed JustinPierce closed 10 years ago

JustinPierce commented 10 years ago

By default, the ValidationSummary control renders the following HTML:

<div class="bmvc-3-validation-summary">
    <div class="validation-summary-valid" data-valmsg-summary="true">
        <ul>
            <li style="display:none"></li>
        </ul>
    </div>
</div>

When I use jQuery Validate to perform client-side validation, the only part of the styling that changes is that validation-summary-valid becomes validation-summary-errors. This works as expected.

However, when I perform server-side validation, the bmvc-3-validation-summary is rendered with the classes alert and alert-danger:

<div class="alert alert-danger bmvc-3-validation-summary">
   <div class="validation-summary-errors" data-valmsg-summary="true">
        <span>Validation summary message.</span>
        <ul>
            <li>Field error message.</li>
        </ul>
    </div>
</div>

This combination of behaviors makes it difficult for me to style the summary consistently. If I style .validation-summary-errors to look like alert-danger, then it looks correct during client-side validation, but I get an alert wrapped in an alert during server-side validation. I can work around it with some convoluted CSS, but it's starting to feel like I'm fighting against your library rather than working with it.

At this point, I would prefer it if no additional classes were added to the summary in either case, so I can at least maintain control in both situations in the same way.

DmitryEfimenko commented 10 years ago

These styles are applied in order to maintain Bootstrap-ish look of the validation summary. I've created a simple JavaScript in order to make the behaviour of server side and client side (unobtrussive) validation the same. You can download it here. Notice that this helpers has more things, not only related to ValidationSummary. Please examine to see what is most useful to you. Let me know if this does not work for you for any reason.

DmitryEfimenko commented 10 years ago

I understand the issue is resolved. Closing issue.