Single select with checkbox in repeating group

The Goal

  • Enable the selection of only one item
  • If another item is selected, the checked mark switches to that item

The Approach

  • Set the selected item into a custom state of a text element, which also displays which item is selected
  • This is being done through a workflow, when the checkbox is selected
  • Use a dynamic state on the checkbox, which checks if the current item is the selected

As you can see, the last point fails. The dynamic state on the checkbox is not working. But why?

I’ve also tested this with radio button, it’s the same phenomena.

It should be possible to do what you want, but you might actually be better off creating your own mutually exclusive selection indicator. It requires less logic and allows you to fully customize the appearance.

The basic approach is to store the current selection in a custom state (like you’re doing - although I usually put the custom state on the RG itself) and then use conditionals on the RG to alter the appearance of the selected item - i.e. when current cell’s Thing is selected Thing.

This example uses a list of Text types and stores the currently selected cell’s index in a custom state; but for a DB “Thing”, I’d create a custom state of the same data type listed in the RG and set that state to the “current cell’s Thing” when a list item is clicked.

(And by changing the custom state to a list, one can easily create a custom multi-selection widget.)

Hope it’s helpful.

1 Like

Thanks for your reply. I’ve moved the custom state to the RG. It produces the same results as before and it is also exactly the same amount of logic.

Maybe I don’t really understand your suggestion:

I thought, that’s what I was doing.

Again, that’s what I was doing.
image
In my understanding, this logic should only show a checked status, when the DB Thing in the row equals the DB Thing on the RG. But it doesn’t. It completely ignores this rule.

That’s what I was doing. First with the custom state on the text element and now on the RG, both with the same result.

I mentioned that purely as a personal preference. It has no effect whatsoever on how things behave. I just find that the expression “reads” better - e.g. “RepeatingGroup’s selected_item”.

No, that simply sets the initial state of the checkbox when it first appears on the page. Once a checkbox is clicked, the initial state (Preset status) no longer applies.

If you want it to work, then you’ll need to jump through hoops to ensure the checkbox isn’t actually clicked (such as making sure the checkbox is behind the element to be clicked) so that its Preset status is always honored. However, you’d be making things more difficult than they need to be. You’re attempting to use an input element as dynamic output.

As I said, it can be done, but it’s going about it the hard way. You’d be better off just using an icon instead of a checkbox input element. Just use a conditional to change the icon. (Or simply change the appearance of the row somehow to indicate that it’s the selected row.)

And lastly, as a general UI convention, checkboxes are typically used for multiple selection. A radio button would be more appropriate for mutually exclusive selection.

Good luck! :slightly_smiling_face:

1 Like

OK. Thanks, I get it.

In short: Use two checkbox icons on top of each other to simulate the checkbox behavior. One checked and one unchecked. Then use conditions to control their behavior.

Same can be done of course with radio buttons, if you want to follow the conventions.

Only need one icon element. Use a conditional to change which icon is shown.

EDIT

By the way (just to clarify), when I say “conditional”, I’m referring specifically to the Conditional tab of the properties editor - not an Only when condition in a workflow.

1 Like

but why not radio buttons?

This topic was automatically closed after 70 days. New replies are no longer allowed.