2

I want to validate name field in this code..

<script type="text/ng-template" id="add.html">
    <div class="modal-header">
        <h3 class="modal-title">ADD</h3>
    </div>
    <div class="modal-body">
        <table class="add-table">
            <form name="myForm">
                <tr>
                    <div class="form-group">
                        <td>
                            <label>name:</label>
                        </td>
                        <td>
                            <input type="text" name="name" ng-model="user.name"
                                placeholder="Name" required=""></input>
                            <span class="error" ng-show="myForm.name.$dirty">Required</span>
                        </td>
                    </div>
                </tr>
            </form>

        </table>
    </div>
</script>

The expression myForm.name.$dirty does not evaluate and return any value. What am I doing wrong here?

6
  • Could you describe the issue that you're having? Commented Jan 21, 2015 at 6:20
  • <span class="error" ng-show="myForm.name.$dirty">Required</span> ng-show="myForm.name.$dirty" never become true. $dirty,$error never evaluate. Commented Jan 21, 2015 at 6:39
  • Nothing appears to be wrong. Commented Jan 21, 2015 at 6:45
  • why this is not working? Commented Jan 21, 2015 at 6:50
  • Create a plunker or add a code snippet to your OP. Commented Jan 21, 2015 at 6:51

1 Answer 1

2
  1. Try moving your <table> inside the <form>.
  2. Also try using $invalid instead of $dirty.
Sign up to request clarification or add additional context in comments.

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.