question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle checkbox groups (group values)

See original GitHub issue

Question

I was wondering if there’s a way to handle checkbox groups. Sprig exposes a variable with the same handle as the name of an input, but checkbox groups share a name with an empty array []. All the values are being sent through ok in the request, but are not combined.

audience[]: 6038
audience[]: 6039
audience[]: 6040

I can’t really make a twig variable with those brackets in the name, so I’m wondering if there’s a way to drop the brackets behind the name and I can get all the values in a comma seperated string. That way I can use the “audience” variable and the comma separated list is easy to |split(',') so I can use them in an Array to check for checked states.

If I remove the array notation it works, but I only get the last value.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
jan-dhcommented, Dec 10, 2020

@j-greig yep I got it working. Hit me up on Craft discord if you want some more info. I used @bencroker 's example from above and got it working

0reactions
bencrokercommented, Dec 10, 2020

Check out sprig.pushUrl(url), probably the simplest solution, also explained in this video: https://putyourlightson.com/sprig/videos#7.-pushing-url-updates

Read more comments on GitHub >

github_iconTop Results From Across the Web

Checkboxes - The complete HTML5 tutorial
Checkboxes. Using checkboxes is a good option when you want to give your visitors the option to choose several items from a group...
Read more >
Automatically check related checkboxes when group ...
Step 1 - Figure out how to store your relationship between Groups and Persons in JavaScript. Something like this should be adequate:
Read more >
React Tutorial – How to Work with Multiple Checkboxes
Handling multiple checkboxes in React is completely different from how you use regular HTML checkboxes. So in this article, we'll see how to ......
Read more >
Implementing Grouping Checkbox Behavior with Angular ...
The first one is responsible for querying the group checkbox element and interacting with it: The second one is responsible for interacting with ......
Read more >
Select Values of Checkbox Group with jQuery - Dot Net Tutorials
In this article, I am going to discuss How to Select Values of the Checkbox Group with jQuery with Examples. Select Values of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found