Skip to content

Add support to onboard error message explicitly. #125

@tshi0912

Description

@tshi0912

Hi huei90,
First of all, thanks to provide so useful validation module in angular world. I like it very much.
It's powerful to validate the form input, textarea and select control in client side, but it's only in client side.
In many cases, we want to provide a consolidated way to feed back the error messages from server side validation to the specific form controls, say, validate whether the userName is duplicated and show the "user name xxx is occupied" label beside the userName input. Since the validation is occurred on server side, we can't pre-define the errors in front-end rules. So if the module provide such a API

$validationProvider.showErrors(form, errors)

It will be very helpful. Hence we can config the consolidated error/exception handling in angular config:

.config(['app', '$httpProvider', '$validationProvider', function (app, $httpProvider, $validationProvider){
    $httpProvider.defaults.transformResponse.push(function (data, headersGetter) {
        ...
        else if(data.code === 'VALIDATION_ERROR'){
            var forms = app.$rootScope.forms || {};
            var form = forms[headersGetter('x-form-id')];
            $validationProvider.showErrors(form, data.fieldErrors);
        } 
        ...
    }
} 

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions