Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Slider toggle issues in Service Portal

dianemiro
Kilo Sage

Hi Everyone,

I am using a slider toggle for a custom widget in Service Portal. I came across an issue wherein if I clicked on multiple sliders, the sliders turns to a checkbox. Anyone have any idea what's wrong? Here is my code:

HTML:

<label ng-click="c.subscribe()">
        <input class="subs-switch" type="checkbox" data-toggle="toggle" data-on=" " data-off=" " data-size="mini" data-style="ios">
        ${Subscribe to all}
</label>

Client Script:

c.subscribe = function(){
   c.data.action = "subscribe";
   c.server.update().then(function(){
      c.data.action = undefined;
   });
}

CSS:

.subs-switch{
  width: 34px;
  height: 20px;
}

.toggle.ios, .toggle-on.ios, .toggle-off.ios { 
  border-radius: 20px; 
}
.toggle.ios .toggle-handle { 
  border-radius: 20px; 
}

.toggle-on {
  background-color: #4696EC;
}

Here is a screenshot of the issue:
find_real_file.png

Regards,
Diane

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @Diane Miro ,

I was not able to guess the issue in your code it looks fine but not sure what happened but may be its CSS problem but I tried with some different code  and it worked please try it and let me know

Print them in loop ng-repeat may be you might have used to render multiple radio buttons same way do it for my below code

HTML:

<label class="switch" ng-click="c.subscribe()">
  <input type="checkbox" checked>
  <span class="slider round"></span>
</label>
<p>
  
<p>${Subscribe to all}</p>
  

client controller:

api.controller=function() {
  /* widget controller */
  var c = this;
	c.subscribe = function(){
		alert('test');
   c.data.action = "subscribe";
   c.server.update().then(function(){
      c.data.action = undefined;
   });
};
};

 CSS:

.switch {
position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

Please mark my answer correct if it is helpful to you

View solution in original post

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

Hello @Diane Miro ,

I was not able to guess the issue in your code it looks fine but not sure what happened but may be its CSS problem but I tried with some different code  and it worked please try it and let me know

Print them in loop ng-repeat may be you might have used to render multiple radio buttons same way do it for my below code

HTML:

<label class="switch" ng-click="c.subscribe()">
  <input type="checkbox" checked>
  <span class="slider round"></span>
</label>
<p>
  
<p>${Subscribe to all}</p>
  

client controller:

api.controller=function() {
  /* widget controller */
  var c = this;
	c.subscribe = function(){
		alert('test');
   c.data.action = "subscribe";
   c.server.update().then(function(){
      c.data.action = undefined;
   });
};
};

 CSS:

.switch {
position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

Please mark my answer correct if it is helpful to you

Thank you, Mohith. The issue is with my css. This is now working as expected. I appreciate your help on this!

Regards,
Diane