Reset/Clear CollectionView checkbox

I have a List Collection (CollectionView) with the action type set to Checkbox.

I created a Checkbox press event handler for it that displays an alert if a certain field of the items has a certain value.

In the Alert, I have an OK trigger that triggers a query.

The issue I have is with the Cancel option of the alert. If user clicks Cancel, the query doesn't run, but the checkbox remains checked, which is misleading.

So my questions are:

  1. How do I prevent the checkbox from being checked if a condition is not met?
  2. Or, how can I go about clearing the checkbox if user clicks Cancel in the alert?


  1. The checkbox on collectionView doesn't currently support a disabled prop, but you can keep a checkbox value constant by syncing it with a temporary state variable and then updating that temporary state variable on every checkbox press event.
    Screenshot 2023-07-20 at 10.38.53 AM
    . Then in my checkbox event handler I apply my default values:

    The way this works is, whenever state1.value updates (even if it's updated to the same value as before), all of the default checkbox values are re-computed and then re-applied even if their value didn't change.

  2. The Visible event handler will trigger on the original screen when the user taps Cancel or OK, so you can run some validation at that point and correct the checkbox state.

I see, thanks I'll give it a go. I hadn't considered the Visible screen handler approach.

For the clicking of the checkbox, I wouldn't want it to be disabled. Rather, it would be clickable, but whether the "checking" actually works would be conditional.

So the steps would be:

  1. Click checkbox
  2. Check if condition met
  3. Toggle checkbox accordingly (if condition met and checkbox is currently checked, then uncheck, etc.)

Basically, it would effectively be an "editable" prop.

This is different from a disabled prop, because a disabled prop wouldn't allow for the clicking to work in the first place, and thus no alert would get conditionally displayed.

Yeah, exactly. Think of it like

  1. click the checkbox & fire checkbox press handler
  2. do some work, possibly validate with an asynchronous service etc
  3. possibly revert the check action

What I meant above is that the logic should prevent the checkbox from being clicked/toggled, so you wouldn't have to revert it afterwards.

Having checkboxes that are toggled then reverted is like having queries that first run and then get reverted by some condition.

Yeah, unfortunately not currently possible with the List Collection!

I understand. For right now, I got around it by simply retriggering the query on Cancel, which reinitializes the default value of (all) checkboxes.

I will try the temp state suggestion shortly.

1 Like