Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material input validation error messages

I'm trying to write an app using Angular-Material and I have a form that has some required fields that needs input validation. I've attempted following the example from the angular-material page under errors, but when I view the code in the browser, the error messages will still appear even if stuff is entered into the fields

Error messages displayed on the entered fields

My jade template looks like this:

form(name="accountForm")
    div(layout="row",layout-sm="column")
        md-input-container
            label Name
            input(name="acctName",ng-model="account.name",required)
            div(ng-messages="accountForm.acctName.$error")
                div(ng-message="required")
like image 318
mikeyGlitz Avatar asked Jul 02 '15 02:07

mikeyGlitz


1 Answers

I didn't realize that ng-messages was a separate Angular module. Since this was a Node project, I imported angular messages using npm

npm install -S angular-messages

Then I modified my angular module code

var app = angular.module('MyApp', ['ngMaterial', 'ngMessages']);

... and it worked!

validated fields with hidden messages

like image 70
mikeyGlitz Avatar answered Oct 16 '22 01:10

mikeyGlitz