I have to validate a form with a directive, for to AngularJS can to be able to enable or disable the submit form button.
I have a function in jQuery, but I need that AngularJS watches this behavior.
This function compares inputs to prevent duplicate information in each one.
<form id="myform">
<table>
<tr>
<td><input name="currency1" class="required" unique="currency"/></td>
</tr>
<tr>
<td><input name="currency2" class="required" unique="currency"/></td>
</tr>
<tr>
<td><input name="currency3" class="required" unique="currency"/></td>
</tr>
<tr>
<td><input name="currency4" class="required" unique="currency"/></td>
</tr>
</table>
This is the function
jQuery.validator.addMethod("unique", function(value, element, params) {
var prefix = params;
var selector = jQuery.validator.format("[name!='{0}'][name^='{1}'][unique='{1}']", element.name, prefix);
var matches = new Array();
$(selector).each(function(index, item) {
if (value == $(item).val()) {
matches.push(item);
}
});
return matches.length == 0;
},
"Valor Repetido"
);
jQuery.validator.classRuleSettings.unique = {
unique: true
};
$("#myform").validate();
$("#validate").onBlur(function() {
$("#myform").valid();
});
and CSS
label.error { color: red }
Can anyone help me?