3

I my form I have some input controls which are bounded with controller's scope data. Based on users selection I am bounding selected item by using ng-model to input controls.

I am validating those inputs by using ng-maxlength ,minlength ,ng-pattern and other inbuilt validation directives.

Class for highlighting the invalid values.

.ng-invalid { border-color:red; }

But when user wants to add a new product, then I am creating an empty object and adding it to controller's scope data.

At the very first time while creating new item I don't want to highlight every thing with red, because very thing is empty.

Is there any way by which I can highlight invalid input on their focus and after it will show as invalid until use put some valid values in it.

When use select any existing data then I am validating control at that movement.

5
  • Provide the rest of the code too. Commented Jan 24, 2016 at 6:40
  • @Claies i am adding object with properties and their values are undefined by default. Commented Jan 24, 2016 at 6:48
  • @Claies adding object with no properties also not working. Commented Jan 24, 2016 at 6:51
  • without showing the code you are using to create the new object, and the HTML with the validation rules on it, it's difficult to know what to suggest. Commented Jan 24, 2016 at 6:59
  • you can use chained css, i.e. .ng-dirty.ng-invalid Commented Jan 24, 2016 at 7:17

1 Answer 1

2

You can use forms' $pristine as a condition for your classes.

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.