0

Hi All of the angular developer, I am fetching a validation problem with angular js. I can do the validation under the Form, I can check every validate field by Form in angular js. but i want to do the same job by using Div instead of Form. many people suggested me that you can do by angular directives. but how? They did not clear to me.Here how will i check all validate directives under the Div?. I have not found any solution. Anyone have an idea or solution?. I have given my example below. now i want to validate this by using angular js directives. Thanks

    <div name="userForm" novalidate>

        <!-- NAME -->
        <div class="form-group" ng-class="{ 'has-error' : userForm.name.$invalid && !userForm.name.$pristine }">
            <label>Name*</label>
            <input type="text" name="name" class="form-control" ng-model="user.name" required>
            <p ng-show="userForm.name.$invalid && !userForm.name.$pristine" class="help-block">You name is required.</p>
        </div>

        <!-- USERNAME -->
        <div class="form-group" ng-class="{ 'has-error' : userForm.username.$invalid && !userForm.username.$pristine }">
            <label>Username</label>
            <input type="text" name="username" class="form-control" ng-model="user.username" ng-minlength="3" ng-maxlength="8">
            <p ng-show="userForm.username.$error.minlength" class="help-block">Username is too short.</p>
            <p ng-show="userForm.username.$error.maxlength" class="help-block">Username is too long.</p>
        </div>

        <!-- EMAIL -->
        <div class="form-group" ng-class="{ 'has-error' : userForm.email.$invalid && !userForm.email.$pristine }">
            <label>Email</label>
            <input type="email" name="email" class="form-control" ng-model="user.email">
            <p ng-show="userForm.email.$invalid && !userForm.email.$pristine" class="help-block">Enter a valid email.</p>
        </div>

        <button type="button" ng-click="Save()" class="btn btn-primary">Submit</button>

    </div>
8
  • try ng-form on the div Commented Jun 8, 2014 at 3:42
  • why would you care about using a form? is just a container you can style it as a div and keep the nice features that using forms in angular gives you Commented Jun 8, 2014 at 3:44
  • Hi, @Khanh TO can you give me a example? this will be very helpful to me. if you send a sample project. thanks for your reply. Commented Jun 8, 2014 at 3:45
  • Hi, @DayanMorenoLeon I have explained another question. please check my question stackoverflow.com/questions/24014054/… Commented Jun 8, 2014 at 3:48
  • so you have a problem with nested forms thats exactly what ng-form directive is for docs.angularjs.org/api/ng/directive/ngForm you can validate your child form and then check if the form is valid when validating the parent form as if the child form was another input field Commented Jun 8, 2014 at 4:12

2 Answers 2

1

Use ng-form:

 <div ng-form="userForm" novalidate>
  ...
 </div>
Sign up to request clarification or add additional context in comments.

Comments

0

You may follow the instruction below

http://www.breezejs.com/documentation/validation http://www.breezejs.com/breeze-labs/breezedirectivesvalidation

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.