Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to make widget checkbox mandatory

asd22
Tera Contributor

i have a checkbox in my widget html:

<label>
  <input type="checkbox" ng-model="c.data.accepted" />
correct</label>

this is not a mandatory checkbox, how do i make it so?

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@asd22 

what's the complete business requirement?

share complete widget code

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Nawal Singh
Tera Guru

Hi @asd22 ,

Update your widget like below- 

NawalSingh_1-1762952914481.png

 

HTML code- 

 

<div>
<label class="mandatory">
  <span ng-if="c.showError" class="ast">*</span>
  <input type="checkbox" ng-model="c.data.accepted"/>
  correct
</label>
</div>
<hr>
<button class="btn btn-primary" ng-click="c.submit()">Submit</button>
  
  

 

CSS Code- 

 

.ast {
  color: red;
  margin-right: 4px;
  font-size:20px;
  weight: 16px;
}

 

Client script code- 

 

api.controller=function() {
  /* widget controller */
  var c = this;
	
  c.submit = function() {
    if (!c.data.accepted) {
      c.showError = true;
      return;
    }
    c.showError = false;
    // continue your submit logic
		
}
};

 

Please test and let me know your feedback!!

 

If you found my response helpful, please mark it as helpful and accept it as the solution.

Thank you
Nawal Singh

we already have a submit button, i cant add a new one. and the widget is huge so its hard for me to show where our submit button is in the script

Hi @asd22 

The way above logic is configured in the same way you need to implement your widget.

if you share your code or screenshot  then only I can help you otherwise its very hard to understand how you have configured your widget structure!!

 

take the above logic as example and try to implement.

 

If you found my response helpful, please mark it as helpful and accept it as the solution.

Thank you
Nawal Singh