Snipcart-checkbox checked by default

Hello!

I want to add a subscribe to newsletter button to the billing box on the checkout page.
Is it possible somehow to set it to checked by default?

Thanks!

@nadorivan Just add “checked” inside the checkbox parameter and it will work

It seems that ignores “checked”. I guess it uses “v-model” under the hood, in that case “checked” is ignored. If I add the checkbox as an , then of course it works, but then “id” is not generated.

Could a Snipcart developer please confirm if it’s possible to make checked by default?

Hi there!

We are indeed using the v-model attribute in Vue right now for our form fields. In order to set the default value of any custom field, you can use our JS SDK to update the cart data like in this example : Set custom field value - CodeSandbox

Let me know if this works for you,
Cheers!

Hi!

Thank you, it is working now!

Cheers!

Is this still a workable method?

I tried it and I get error logs in my console like 'TypeError: Cannot read properties of undefined (reading ‘api’) and ‘The #snipcart div was removed from the document. This may happen when a frontend library is used to render the div. You should only render it once, or it might prevent the cart from working.’

Hey @MartyMcFly yes this is still valid and if you are having this error when looking at the demo linked above, simply refresh the preview browser in the UI (it’s a quirk from how codesandbox reloads the preview).
image

Yes works for me now. Had some classical little stupid mistake. Thank you

1 Like