Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Sean Warrener
Sean Warrener
4,398 Points

AngularJS Help: Checking two fields and setting a multi-line field to required if fields are blank

I'm working on a form in AngularJS in which if two fields are left blank that an explanation field will be required to fill out on submission of the form.

I think I have an idea of how it should look after clicking through and seeing how to determine if a field is blank, but it's not hiding the message after there is content in the fields:

<form ng-app=""> <strong>Max Num:</strong> <input id="Max Number" ng-model="maxNum" tabindex="1" type="number" /><br /><br /> <strong>Numerator:</strong> <input id="Numerator" ng-model="theNum" min="1" max="{{theDen}}" name="Numerator" size="10" maxlength="20" tabindex="2" type="number" /><br /><br /> <strong>Denominator:</strong> <input id="Denominator" ng-model="theDen" min="1" max="{{maxNum}}" name="Denominator" size="10" maxlength="20" tabindex="3" type="number" /><br /><br /> <strong>Notation:</strong> <textarea rows="4.5" cols="50" id="Notation" ng-required="[theNum =='undefined' ||theNum =='null' || theNum.length==0] && [theDen =='undefined' ||theDen =='null' || theDen.length==0]" name="Notation" maxlength="255" tabindex="4" type="text"></textarea><br /> <br /> <div ng-if="[theNum =='undefined' ||theNum =='null' || theNum.length==0] && [theDen =='undefined' ||theDen =='null' || theDen.length==0]"> <div ng-messages="myForm.myName.$error" style="color:red" role="alert"> <div ng-message="required">You have no numerator or denominator data for this set.<br />Please explain in notation field.<br /><br /></div> </div></div><input tabindex="5" type="submit" /> </form>

I unfortunately can't add any additional js apps since I'm on Drupal for this form, so the link to the angular components are in the CMS editor and any other JS being pulled in from inside is hit or miss when being called.