Skip to content Skip to sidebar Skip to footer

Validation Of Angular Form Without Submit Button

I am using anuglar.js form validation. I want to check validation without form submit button. This is my html.
Copy

Check angular docs

Solution 2:

HTML

<divng-app="myApp"><formname="cutome_form"ng-submit="submitForm()"novalidate><inputtype="text"name="name"class="form-control"ng-model="Name"placeholder="Name"maxlength="50"required><divng-show="cutome_form.name.$dirty && cutome_form.name.$invalid"><spanclass="error"ng-show="cutome_form.name.$error.required">The field is required.</span></div><divclass="form-group"><labelfor="pwd">Alias:</label><inputtype="text"name="alias"class="form-control"ng-model="Alias"placeholder="Alias"maxlength="50"required></div><divng-show="cutome_form.alias.$dirty && cutome_form.alias.$invalid"><spanclass="error"ng-show="cutome_form.alias.$error.required">The field is required.</span></div><buttontype="submit"ng-disabled="cutome_form.$invalid">Submit All</button></form></div>

directive

  .directive('ngModel', function() {
    return {
        require: 'ngModel',
        link: function(scope, elem, attr, ngModel) {
            elem.on('blur', function() {
                ngModel.$dirty = true;
                scope.$apply();
            });

            ngModel.$viewChangeListeners.push(function() {
                ngModel.$dirty = false;
            });

            scope.$on('$destroy', function() {
                elem.off('blur');
            });
        }
    }
});

Post a Comment for "Validation Of Angular Form Without Submit Button"