ng-if on a portal widget

Jen11
Tera Expert

On a portal widget we have a 'work email address' field and an 'alternate email address' field.  What I am trying to do is if 'work email address' field is blank then 'alternate email address' should be mandatory.  How do I do this?

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If this is a custom widget you'll probably need to post your widget code to get a good answer.

If this is for a widget through the catalog or something like that you can just use the existing form widget and a ui policy.

     <!--Work Email-->
      <div class="form-group col-md-6"
           ng-if="c.registration_mcemployee === 'Yes'"
           ng-class="{ 'has-error' : mcexperiencedr.registration_work_email.$invalid && c.submitted }">
        <label class="control-label" for="registration_work_email">Work E-Mail Address</label> 

        <input id="registration_work_email" name="registration_work_email" type="text"  class="form-control input-md" placeholder="{{data.emp.email}}" readonly
               ng-model="c.registration_work_email"
                >
      </div>
     
     
    

      <!--Alternate E-Mail Address-->
      <div class="form-group col-md-6"
           ng-if="c.registration_mcemployee === 'Yes'"
     
   
          
           ng-class="{ 'has-error' : mcexperiencedr.registration_personal_email.$invalid && c.submitted }"
           >

        <label class="control-label" for="registration_personal_email">Alternate E-Mail Address</label> 

        <input id="registration.email" name="registration_personal_email" type="text" class="form-control input-md"
               ng-model="c.registration_personal_email"
               ng-required="!c.registration_work_email"
               >
      </div>

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you're checking to see if it's empty or not, you could try

ng-required="c.registration_work_email == ''"

instead of:

ng-required="!c.registration_work_email"

that didn't work