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

2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The problem with this solution, is that I had to put ALL FIELDS of the forms in the validation, better is looping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.