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.

Default value for checkbox is displayed undefined

Ujjwal1
Tera Contributor

hi 
i have used checkbox in portal widget. by default value is checked.

 

I am trying to get checkbox value , it is displayed as undefined. Ideally value should be retrieved as  true. Please suggest.

 

screenshot:

   <label><input type="checkbox" name=user_access" ng-model="data.user_access" ng-checked="true"> User Access</label><br/>
//value in client script
 spUtil.addInfoMessage("hi01" + $scope.data.user_access);

Ujjwal1_0-1743670293189.png

 

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Ujjwal1 ,

 

Are you populating the value in the Server Script? If not please add something like this there:

 

data.user_access = true;

 

Then you can change the HTML to this (please note there was also a missing double-quote in the "name" attribute, which is fixed below):

 

<label><input type="checkbox" name="user_access" ng-model="data.user_access">User Access</label>

 

Regards,

Robert

 

View solution in original post

6 REPLIES 6

Ujjwal1
Tera Contributor

Thanks @Robert H  - for response. provided solution worked .

 

Just to know - any reason why below code did not work.

ng-checked="true"

 

 

Thanks

Ujjwal

Hello @Ujjwal1 ,

 

"ng-model" binds the input to a property on the scope, but you need to defined that property first. 

Also, "ng-model" should not be used together with "ng-checked", else there will be unexpected results. 

 

You can find more details in the AngularJS documentation for "ngModel" and "ngChecked". Unfortunately I cannot add the links to this message, else it will be deleted.

 

Regards,

Robert