0

I have the following form:

        <form name="newCollectionForm" ng-submit="onSubmit()">
            <md-input-container class="md-block">
                <label>Name</label>
                <input name="collection"
                       ng-model="new_collection_model"
                       ng-trim="true"
                       ng-minlength="3"
                       ng-maxlength="50"
                       md-maxlength="50"
                       required>
                <div ng-messages="newCollectionForm.collection.$error">
                    <div ng-message="required">You must supply a name for the Collection.</div>
                    <div ng-message="maxlength">The name must no contain more than 50 characters.</div>
                    <div ng-message="minlength">The name must be at least 3 characters.</div>
                </div>
            </md-input-container>
        </form>

The only Issue is that it does not show the errors messages. It only show the error state but without showing the corresponding message.

I have tried many variants and no success.

Any help?

2
  • add novalidate attribute in form Commented Jun 12, 2016 at 15:38
  • @ArpitSrivastava I had that directive but happens the same Commented Jun 12, 2016 at 15:42

2 Answers 2

1

I have created a plunker for you.

https://plnkr.co/edit/MvFaXjseWt8ILRpsbftq?p=preview

you will have to do the following thing to make your code to work.

1: inject ngMessages in your module.

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

2: include this js file in your code.

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.16/angular-messages.min.js"></script>

Hope this will help you.

Sign up to request clarification or add additional context in comments.

6 Comments

I have both (ngMessages) injected and the resource link too.
could you just check your code with the plunker code. I have used html provided by you only. Or if you have any plunker where i can check the problem
Ok, I'm going to check it out.
I open your link and show this: Unable to connect to any application instances.
Plunker is down currently
|
0

Well, at least I could show the messages making some changes:

        <form name="newCollectionForm" ng-submit="onSubmit()" novalidate>
            <md-input-container class="md-block">
                <label>Name</label>
                <input name="collection"
                       ng-model="new_collection_model"
                       ng-trim="true"
                       ng-minlength="3"
                       ng-maxlength="50" md-maxlength="50" required>
                <div ng-show="newCollectionForm.collection.$error" role="alert">
                    <div class="form_error" ng-show="newCollectionForm.collection.$error.required">You must supply a name for the Collection.</div>
                    <div class="form_error" ng-show="newCollectionForm.collection.$error.maxlength">The name must no contain more than 50 characters.</div>
                    <div class="form_error" ng-show="newCollectionForm.collection.$error.minlength">The name must be at least 3 characters.</div>
                </div>
            </md-input-container>
        </form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.