0

I have a form field. The problem is that i want to display the errors when user interact with the field. I am using the below code :

<form class="" name="myForm" novalidate>
      <input type="text" placeholder="First Name" class="user-icon" name="fname" ng-model="user.fname" required>
        <div ng-show="myForm.fname.$dirty && myForm.fname.$error.required">First Name is required.</div>

      <input type="text" placeholder="Last Name" class="user-icon" name="lname" ng-model="user.lname">
        <div ng-show="myForm.lname.$error.required">Last Name is required.</div>

      <input type="text" placeholder="Email" class="email-icon" name="email" ng-model="user.email">
        <div ng-show="myForm.email.$error.required">Email is required.</div>

      <input type="text" placeholder="Password" class="password-icon" name="password" ng-model="user.password">
        <div ng-show="myForm.password.$error.required">Password is required.</div>

      <input type="text" placeholder="Confirm Password" class="password-icon" name="conf_password" ng-model="user.conf_password">
        <div ng-show="myForm.conf_password.$error.required">Confirm Password is required.</div>


        </form>

But the code is not working. Please correct me if i am wrong?

1 Answer 1

2

You forget to add required

and add novalidate in your form

Try like this

<input type="text" placeholder="First Name" class="user-icon" name="fname" ng-model="user.fname" required>
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the help. But it's still not working. I don't want to use HTML required
please provide your full html code .. it'll be better if you can provide plunkr
Don't forget to add form name myForm

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.