I have built a user macro that displays as a button that, when selected automatically de-selects any checkboxes on the page.
The macro works successfully, but doesn't actually update the page so, when you refresh the page, the checkboxes are still selected.
How would I need to update the macro so that it saves the changes to the page?
Hi, @Matt Parks! 👋
Can you give more background info on how you've built the user macro?
Here's the code of the macro. Not much to it. I would assume that I would put something right before the </script>, but I don't know what and haven't been able to figure it out.
## @noparams
<script>
function myFunction() {
Array.from(document.getElementsByClassName('checked')).forEach((el) => el.classList.remove('checked'));
};
</script>
<button type="button" id="myBtn" onclick="myFunction()">Try it</button>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wouldn't have thought that I needed to save the changes, since I don't have to if I'm just manually de-selecting a checkbox, but the checkboxes don't stay de-selected after refreshing the page or navigating away and then back.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So your macro's JavaScript currently only changes the visual state on the page (removing the CSS class 'checked'
), but it doesn't actually update or save the page content in Confluence. This is why after a refresh, the checkboxes revert back.
Confluence stores page content on the server, and your JS runs only on the client side. To save the changes, you need to update the page content via Confluence’s API or editing framework - something that isn't achievable by client-side JS alone in a user macro.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the explanation. I'll let my macro developer know that this is what they'll need to do.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's likely that the front-end code listens to an event that happens when the checkbox is clicked on. Maybe you could try changing
el.classList.remove('checked')
to
el.click()
in your script and see if that makes any difference?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately, the only difference it makes is that the checkboxes are no longer un-checked. I appreciate the assistance, though!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.