0

Is it possible to set the Angular "required" directive/attribute to other elements except input fields? I have several lists on a page where the user can check the entered data from pages before ... user should only be able to "submit" (send data to database...) if the "required" data is complete.

So how to check data in arrays which is displayed in list views? (ok, looping through arrays and check the values (is empty?) is possible - but i think there are better solutions... maybe a custom directive?)

5
  • 1
    Have you checked this stackoverflow.com/questions/15360094/… Commented Jul 10, 2013 at 13:16
  • Checked this and it´s very helpful, but how could i do this depending on more than just one list element? I´ve added the name attribute with the same name (name="required") to more than one element, and button looks like this ng-disabled="!form.required.$valid"... but this doesn´t work, button is still disabled even when the elements are not empty... Commented Jul 10, 2013 at 13:41
  • Can you share some code in fiddle. name property of the element it used to reference the element. You do not set name=required, required is a independent attribute Commented Jul 10, 2013 at 13:53
  • that´s clear... it´s my first fiddle, don´t know how it´s not recognizing Angular --> jsfiddle.net/enND2/2 Perhaps because i´m using Jquery mobile with angular ... Commented Jul 10, 2013 at 14:23
  • 1
    List such as <ol> do not have a concept of selection, you need to implement it yourself, or use html type <select> Commented Jul 10, 2013 at 14:38

1 Answer 1

0

You can set angular validation directives on elements that have ng-model. The ng-model directive has a controller with properties like $error, $invalid, etc. So the ng-model controller acts like a storage for the errors.

If you use more exotic inputs or don't use ng-model I suggest you go "custom directive" way. I've written one such custom directive myself for such scenarios. (http://liviutrifoi.wordpress.com/2013/10/19/angular-custom-validation-with-business-rules/)

I suspect the lists you are using are bound to arrays from a controller. If that's the case you could define a "validation rule" (see my article) in the controller that iterates the arrays and returns a true/false along with an error message. Then you would put a validator directive on a list and a to display the error message. Maybe it helps.

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

Comments

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.