DmitryEfimenko / TwitterBootstrapMvc

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

Successful form validation? #385

Closed speshulk926 closed 9 years ago

speshulk926 commented 9 years ago

Do you know if/how it is possible to use the "has-success" similarly to how "has-error" works now? The user starts typing and once all validation passes it turns green. I don't seem to see anything on it anywhere. Any help would be appreciated!

http://getbootstrap.com/css/#forms-control-validation

DmitryEfimenko commented 9 years ago

You are correct, currently there is nothing in the BMVC .js file that puts class has-success on form-group. However, this is the javascript responsible for dealing with it (lines 6-19 of TwitterBootstrapMvc.js file):

if ($.validator && $('form').length > 0) {
    $('form').each(function () {
        $(this).validate().settings.highlight = function (element) {
            $(element).closest('.control-group').addClass('error');
            $(element).closest('.form-group').addClass('has-error');
        };
    });
    $('form').each(function () {
        $(this).validate().settings.unhighlight = function (element) {
            $(element).closest('.control-group').removeClass('error');
            $(element).closest('.form-group').removeClass('has-error');
        };
    });
}

You can tweak it a bit easily.