Avatar of Sandy V
Sandy V
 asked on

Validations in angularJS

Is there a way to set two fields combined as required field in AngularJS, let's say you have two text fields Product & Order & i need to make sure that atleast one of the field is populated
Angular* Data Validation

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Julian Hansen

Take a look at the ng-required directive https://docs.angularjs.org/api/ng/directive/ngRequired
<input ng-required="expression">

Open in new window


where expression is an expression that checks your model values

<input ng-required="!(model.Product.length || model.Order.length)">

Open in new window


In your controller code
...
 $scope.model = {
    Product: '',
    Order: '',
    ...
 }

Open in new window

Sandy V

ASKER
Here Product & Order are 2 different input fields. Where should i put the ng-required directive?? i thought the only way to achieve this is using a custom directive
ASKER CERTIFIED SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Sandy V

ASKER
Perfect, thanks for the explanation
Your help has saved me hundreds of hours of internet surfing.
fblack61
Julian Hansen

You are welcome.