Solved

angular how do you validate that one of two text boxes has a value

Posted on 2014-03-20
4
612 Views
Last Modified: 2014-04-01
I have two text boxes and I want to validate that one of them was filled in.

<input type="TextBox" name="TextBoxEmailAddress1" ng-model="emailAddress1"/>
<input type="TextBox" name="TextBoxEmailAddress2" ng-model="emailAddress2"/>

Thanks!
0
Comment
Question by:jackjohnson44
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 39944955
do you mean a user must provide an email but it doesn't matter which field they use?

why not just make the first one required and the second one optional?
0
 

Author Comment

by:jackjohnson44
ID: 39957269
I can't change the requirement.  I need to validate that one of the two is filled in. It's a lot more complicated that my simple example.  I can't change the requirement at all.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39957528
Test page : http://jsfiddle.net/nZpZW/2/

<div ng-app="App" ng-controller="Ctrl">
    <form name="form" class="css-form" novalidate>
        <input type="email" name="TextBoxEmailAddress1" ng-model="emailAddress1" ng-required="!emailAddress2" />
        <br />
        <input type="email" name="TextBoxEmailAddress2" ng-model="emailAddress2" ng-required="!emailAddress1" />
        <br />
        <span ng-show="form.TextBoxEmailAddress1.$error.required||form.TextBoxEmailAddress2.$error.required">FILL AT LEAST ONE</span>
        <br />
        <input type="submit" value="SUBMIT"  />
    </form>
</div>

Open in new window

0
 

Author Closing Comment

by:jackjohnson44
ID: 39969541
Thanks!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question