I have the following directive, which I got on the web to use jQuery Validator with Angularjs
app.directive('ngValidate', function () {
return {
require: 'form',
restrict: 'A',
scope: {
ngValidate: '='
},
link: function (scope, element, attrs, form) {
var validator = element.validate(scope.ngValidate);
form.validate = function (options) {
var oldSettings = validator.settings;
validator.settings = $.extend(true, {}, validator.settings, options);
var valid = validator.form();
validator.settings = oldSettings; // Reset to old settings
return valid;
};
form.numberOfInvalids = function () {
return validator.numberOfInvalids();
};
}
};
})
.provider('$validator', function () {
$.validator.setDefaults({
onsubmit: false // to prevent validating twice
});
return {
setDefaults: function (options) {
$.validator.setDefaults(options);
},
addMethod: function (name, method, message) {
$.validator.addMethod(name, method, message);
},
$get: function () {
return {};
}
};
});
What this does is that you can validate a form using Jquery Validate.
My Html
<form id="order-form" class="smart-form" ng-submit="register(order-form)" ng-validate="validationOptions">
<input type="email" name="email">
<input type="password" name="password">
<input type="submit" name="name" value="submitme">
</form>
In my controller I call in the following way
$scope.register = function (form) {
if(form.validate()) {
// Form is valid!
alert('hallo')
}
}
but the line of if(form.validate())
returns form.validate is not a function . If I see the directive you have the form.validate but I do not understand why I get it that it is not a function. More than all my management with directives is not very advanced. I do not know what I can do for form.validate
to run.