"I have to reload the browser to display the toggles."
Change knack-scene-render.any to this instead: knack-view-render.form
knack-scene-render.any is saying "run the code 1 time per page". That's too broad of a rule. That's why after the form reloads, the checkboxes go back to normal again, because the code to make them sliders hasn't run.
Than you for the responses. Tony, I liked your solution and it solved my initial issue. However, I am still left with a similar issue. After submitting the form and then using the "Reload form" link that Knack generates, the toggle shows as a checkbox. I have to reload the browser to display the toggles. Any solution to this?
That issue is happening because multiple "slider round" classes are being created, one for each view on your page. See picture below. These classes are called "slider" not "slider round" but it's the same issue.
That's why it works when you refresh the form, because your form is one "view" and the code is designed to execute on any view. However, this is also why it doesn't work when there are multiple views on a page, because the code will execute once for each view and you end up with multiple "slider" classes. For example, a page with 2 views will run the same code 2 times.
To change this behavior, you want to modify the $(document).on('knack-view-render.any'... to only the specific view_### containing the form.
OR
Write a small snippet of code to check if the class already exists before appending it. For example, if class="slider option" exists already, then you wouldn't append it.
I am getting an issue when I load a form with the toggles. Initially, they are not able to be edited and I have to reload the form to be able to actually toggle the switch.
The same issues seems to be occurring when I return to a form where the toggles have been previously entered and the form submitted. The toggles initially only show the default values and are not editable, then I have to reload the form to get the previously saved toggle positions to display. Anyone else having this issue and any recommended solutions?