Skip to main content
1-Visitor
March 24, 2022
Solved

How to use a toggle button to display true/false status

  • March 24, 2022
  • 2 replies
  • 5080 views

Hello community,

I am working on a dashbboard where I want to use a toggle button to display a OK/NOK value with this toggle.

Already got it working that depending on the status true/false the switch toogles.

But now I want to add some colors to that. I used the CSS widget configurator to create a design for both status:

KS_9688607_0-1648118989845.png

KS_9688607_1-1648119000047.png

Spoiler

.slider-checkbox {
width: 70px!important;
height: 32px!important;
}

.slider-checkbox > .widget-checkbox>input {
display: none
}

.slider-checkbox > .widget-checkbox {
width: 70px!important;
height: 32px!important;
overflow: visible;
}

.slider-checkbox > .widget-checkbox>label {
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: #FF0000;
box-shadow: inset 0px 1px 3px 0px rgba(0,0,0,0.15);
border-radius: 16px;
box-sizing: border-box;
transition: background .2s ease-in-out;
}

.slider-checkbox > .widget-checkbox>input:checked+label {
background: #4CAF51;
}

.slider-checkbox > .widget-checkbox>label>span {
display: block;
margin: 2px;
width: calc(32px - (2 * 2px));
height: calc(32px - (2 * 2px));
position: absolute;
top: 0;
left: calc(70px - 32px);
transition: all .2s ease-in-out;
background: #ffffff;
border-radius: calc(16px - 2px);
z-index: 1;
box-shadow: 0px 1px 3px 0px rgba(0,0,0,0.4);
}

.slider-checkbox > .widget-checkbox>input:not(:checked)+label > span {
background: #ffffff;
}

.slider-checkbox > .widget-checkbox>label::after,
.slider-checkbox > .widget-checkbox>label::before {
line-height: 32px;
background: none;
position: absolute;
left: 0px;
width: calc(70px / 2 - 2px)!important;
height: 32px!important;
vertical-align: middle;
text-align: center;
font-size: 14px;
font-weight: 400 !important;
}

.slider-checkbox > .widget-checkbox>label::before {
color: #ffffff;
border: none!important;
margin: auto!important;
left: 2px;
content: "On";
}

.slider-checkbox > .widget-checkbox>label::after {
color: #aaaaaa;
left: calc(70px / 2 - 2px);
content: "Off";
}

.slider-checkbox > .widget-checkbox>input:not(:checked)+label>span {
left: 0;
}

Unfortunatly the custom class seems not apply the CSS design to the button.

I also found out that in the configurator a small hint is placed to use a checkbox field and modify it with tht CSS code. But both ways did not apply the design to the toggle or the checkbox.

 

May you got a hint for me how to get a solution?

XOXO,

Karma

 

Best answer by GabrielB

Hi @KarMa,

I am the creator of the CSS Widget Configurator. The Slider/Toggle is made from a Checkbox(The legacy one). If you go in the mashup builder and on the widgets panel go to the dropdown to show you ALL the widgets, when you search for a "checkbox" you'll see that it will show you a widget with a small yellow warning sign. That is the Legacy Checkbox widget. The CSS you have will only work on that one.

 

BR,

Gabriel

2 replies

5-Regular Member
March 30, 2022

Hello @KarMa ,

 

pls check and respond whether the below given article link is useful for you:

 

https://www.ptc.com/en/support/article/cs324593

 

Kindly revert back.

 

Regards

Bhawna

GabrielB12-AmethystAnswer
12-Amethyst
April 18, 2022

Hi @KarMa,

I am the creator of the CSS Widget Configurator. The Slider/Toggle is made from a Checkbox(The legacy one). If you go in the mashup builder and on the widgets panel go to the dropdown to show you ALL the widgets, when you search for a "checkbox" you'll see that it will show you a widget with a small yellow warning sign. That is the Legacy Checkbox widget. The CSS you have will only work on that one.

 

BR,

Gabriel

5-Regular Member
April 26, 2022

Hello @KarMa ,

 

Kindly revert back if the given solution works for you.

 

Regards

Bhawna

KarMa1-VisitorAuthor
1-Visitor
June 2, 2022

Hello @GabrielB ,

thanks for the feedback and the hints. I works like you described. Thanks for that!

What makes my curious is that we are adviced from PTC to NOT use legacy widget as they are possilby deleted in future versions.

 

Is there a way to use the configurator also for the actual widgets? Or is it planned to have a configurator for the actual widgets?

 

XOXO,

KarMa