validate
function in module validity
validate(form, control);
validate(form, control);
Asynchronously validates a form or control
Parameters
Param | Type | Details |
---|---|---|
form | object | The form to be validated |
control (optional) | object | A control, within the form, to validate |
Returns
promise
- an angular promise is returned by this function. The promise resolves when all the validation checks on the form have completed. If all the validation rules on the form are valid, the promise resolves as successful. Otherwise, the promise resolves with a rejection.
See Validation Workflow for an indepth look into how validity handles validation.
Usage
Call from within a controller:
controller("ExampleCtrl", ["validity", function (validity) {
validity.validate(/* form */);
}]);
Examples
Example 01: validate a form
controller("ExampleCtrl", ["$scope", "validity",
function ($scope, validity) {
validity.validate($scope.form).then(
function() { console.log("The form is valid") },
function() { console.log("The form is invalid") }
);
}
]);
Example 02: validate a control
controller("ExampleCtrl", ["$scope", "validity",
function ($scope, validity) {
validity.validate($scope.form, $scope.form.username).then(
function() { console.log("The control is valid") },
function() { console.log("The control is invalid") }
);
}
]);
Updated less than a minute ago