-
I'm trying to render the toggle on an hidden checkbox and the result is that the tooggle is of the wrong size and no text inside is shown. style="width: 0px; height: 0px;" Is there a way to render an hidden checkbox in the proper size? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
Hi! 👋 |
Beta Was this translation helpful? Give feedback.
-
Hi @edika99 Can you provide me a minimal html code for reproduce de issue? Thanks |
Beta Was this translation helpful? Give feedback.
-
Take a look at this codepen https://codepen.io/edika99/pen/rNeraJE Look at the different rendeirng size of the hidden checkbox and the normal one. Click on the second toggle to show the hidden checkbox and compare the two size. |
Beta Was this translation helpful? Give feedback.
-
I see the issue. I think forcing render again will works. I'll send you a solution as soon as possible. 😊 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi @g-pane, Is the same problem so a new issue is not needed 😊. In fact, the toggle height and width is calculated considering the max calculated render size of each toggle element (on or off elements). When the original checkbox is hidden, the calculated render size is 0px. I'll give you a workaround as soon as possible, and look for a fix for the next version. |
Beta Was this translation helpful? Give feedback.
-
Ok thanks! But i don't understand (the technical reason) why if i'll inizialize the library after i'll remove the d-none the result is the same as the OP. In his case was hidden, in mine was hidden but showed before the inzialization |
Beta Was this translation helpful? Give feedback.
-
Hi @g-pane, the lib script render all the toggle on document ready, so I imagine the d-none is set before the toggle render. |
Beta Was this translation helpful? Give feedback.
-
I let you a code pen with 2 workarounds for this issue. Work around 1: render on showSkip render on load with data attribute $('#my-selector').onclick((e)=>{
// Add display to element
$('#my-toggle').bootstrapToggle();
}); Work around 2: destroy and render on showDestroy and render the toggle on show with: $('#my-selector').onclick((e)=>{
// Add display to element
$('#my-toggle').bootstrapToggle('destroy');
$('#my-toggle').bootstrapToggle();
}); I'll look for a better fix for the issue, but for the moment I think it can be a good solution. |
Beta Was this translation helpful? Give feedback.
-
I have used the first "workaround" version. For ECMAS version, this is the correct code for all the toggles. document
.querySelectorAll('input[type=checkbox][data-toggle="skip-toggle"]')
.forEach(function (ele) {
ele.bootstrapToggle();
}); I think you can make a sort of "refresh" function, for example made in this way:
|
Beta Was this translation helpful? Give feedback.
Hi @edika99 and @g-pane,
I let you a code pen with 2 workarounds for this issue.
Work around 1: render on show
Skip render on load with data attribute
data-toggle="skip-toggle"
and render the toggle on show with:Work around 2: destroy and render on show
Destroy and render the toggle on show with:
I'll look for a better fix for the issue, but for the moment I think it can be a good solution.