paulyoder / angular-bootstrap-show-errors

An Angular directive for Bootstrap to intelligently show form validation errors
MIT License
331 stars 77 forks source link

Validation not updated on form submit #24

Closed paolosanchi closed 9 years ago

paolosanchi commented 9 years ago

On submit of the form, the control shoould be validated, even if they didn't blur. So I propose to add this $watch:

    scope.$watch(function () {
        return formCtrl.$submitted;
    }, function (submitted) {
        if (submitted)
            scope.$broadcast('show-errors-check-validity');
    });

i've tested it, and it seems to work

paolosanchi commented 9 years ago

ps.. why we just don't check $touched instead of using a blur event? Angular provide every state of the control we need

paulyoder commented 9 years ago

There's usually an action on the controller that is called when a form is submitted, so I recommend performing the scope.$broadcast('show-errors-check-validity') within the controller. I'm leery of performing that validation automatically on form submit because there might be some users that don't want that functionality.

And the reason this directive is using the blur event instead of $touched is because Angular version 1.2 does not have $touched. That was introduced in version 1.3, and I don't want to add it now because the directive could no longer be used in Angular 1.2 apps.