Toggle CMS Toggle button with JS


Is there a way I can use JS to access and toggle the ‘Toggle’ button within a CMS item??

Hey Matt, what Toggle button?
You’ll need to share your readonly project link for us to see what you’re trying to do.

Micheal is right, but im just assuming here you’re talking about the API?

If so, it’s a true/false boolean, so yes you can.

If you mean using JS to click a toggle on the front end, you can just trigger a click event.

Hi Julian,

I am refering to the switch field in the CMS that can be added and used for filtering.

I want to know if it’s possible to access this using JS when a button is clicked on the web page.

Could you add a live and read only link? I don’t know what you mean by “accessing” it

I’m going to hazard a guess here-

You have a CMS collection which contains a switch field, let’s call it Toggle
You are using that for conditional visibility in a collection page or collection list
You want to get and/or manipulate the value of that field for the current item, from script

Getting the value is easy, get bind it to something and read that with your script, or embed it directly into an HTML embed as a variable value.

Setting the value is tricky. You can try using a logic-bound form, and triggering it from script.
You can use external automations like make, with a webhook, API calls, and JS to do the webhook transaction.

Thanks Michael, that is correct. I have 2 CMS collections that are identical. 1st one is ‘Available’, 2nd one is ‘Booked’. I want to toggle (change the state from true to false or on to off if you like) of the switch field in the collection item when i submit a form (click a submit button on the page) to make the CMS item in ‘Available’ not visible and the corresponding CMS item in ‘Booked’ visible.

Did you ever figure this out?? I’m trying to do the same thing.