2

Good morning everyone,

Its possible create a directive (validation) to form level?

what I need is the following:

I have a form which has several fields and also has a button that is disabled while the validation of each of the fields is failed.

I need to create another validation, to check that at least one field of the form is filled.

I found one similar question here: link, but the solution is not the best (i think)

Thank you in advance

Community
  • 1
  • 1
Javier Larios
  • 192
  • 2
  • 9
  • There's an entire page on [angularjs forms and validations](https://docs.angularjs.org/guide/forms) that can help. A search engine query for 'angularjs form validation' also has good results. – Matthew Bakaitis Apr 23 '14 at 15:56
  • The solution to my problem is solved with a Angular filter. See this post http://stackoverflow.com/questions/14347024/angular-form-validation-ng-show-when-at-least-one-input-is-ng-invalid-and-ng-di – Javier Larios Apr 24 '14 at 16:27

1 Answers1

2

My simple answer without knowing more details would be to add a simple function to your controller to check to see if it is valid.

For example:

$scope.isValid = function isValid(){
    return (field1 || field2 || field3 || undefined) !== undefined;
}

Then update your ng-disabled to include it.

ng-disabled="your_form.$invalid || !isValid()"

With more details I could get a better answer.

Shawn C.
  • 6,446
  • 3
  • 34
  • 38