Is there a way to make sn-record-picker field mandatory on the form

rameshg
Giga Expert

Is there a way to make sn-record-picker field mandatory on the form.

I tried ng-required="true" and it is not working.

1 ACCEPTED SOLUTION

Akhil Kumar1
Mega Sage

You can do it via in the below method

 Let's say below is the record pickert to select user's from user table

 

<div class="form-group">
<label>
<span style="padding-right: .25em" title="Mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': c.username.value+'' != ''}"></span><abbr>${Requester Name}</abbr>
<i class="fa fa-check-circle" style="color: #21b384;" ng-if="c.username.value"></i>
<i ng-if="!(c.username.value)" class="fa fa-exclamation-triangle" style="color:#cc2114"></i>
</label>
<div class="input-container">
<span></span>
<sn-record-picker  sn-model="c.username" sn-disabled="c.data.validator.empidReadonly" field="c.username" table="'sys_user'" display-field="'name'" display-fields="'email,user_name,u_local_name,u_local_department'" value-field="'sys_id'" search-fields="'name,user_name,u_local_name'" page-size="500" placeholder="Employee ID" default-query="data.hpavalidator.userQuery"></sn-record-picker>
</div>
</div>

 
sn-record-picker when the value is empty 
 
In the above code check the CSS style which i have added (ng-class added)
 
find_real_file.png
 
 
sn-record-picker when the value is not empty ( when the value is filled it will show the field as shown below)
 
find_real_file.png
 
Also if you want to do the validation on Submit or any action Add the below code in the client controller
 
 
if (c.username.value == '' || c.username.value == undefined) {
 
//if the value is empty the control will reach inside this condition // add alert or error message

}
 
 
 

View solution in original post

1 REPLY 1

Akhil Kumar1
Mega Sage

You can do it via in the below method

 Let's say below is the record pickert to select user's from user table

 

<div class="form-group">
<label>
<span style="padding-right: .25em" title="Mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': c.username.value+'' != ''}"></span><abbr>${Requester Name}</abbr>
<i class="fa fa-check-circle" style="color: #21b384;" ng-if="c.username.value"></i>
<i ng-if="!(c.username.value)" class="fa fa-exclamation-triangle" style="color:#cc2114"></i>
</label>
<div class="input-container">
<span></span>
<sn-record-picker  sn-model="c.username" sn-disabled="c.data.validator.empidReadonly" field="c.username" table="'sys_user'" display-field="'name'" display-fields="'email,user_name,u_local_name,u_local_department'" value-field="'sys_id'" search-fields="'name,user_name,u_local_name'" page-size="500" placeholder="Employee ID" default-query="data.hpavalidator.userQuery"></sn-record-picker>
</div>
</div>

 
sn-record-picker when the value is empty 
 
In the above code check the CSS style which i have added (ng-class added)
 
find_real_file.png
 
 
sn-record-picker when the value is not empty ( when the value is filled it will show the field as shown below)
 
find_real_file.png
 
Also if you want to do the validation on Submit or any action Add the below code in the client controller
 
 
if (c.username.value == '' || c.username.value == undefined) {
 
//if the value is empty the control will reach inside this condition // add alert or error message

}