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:
How do I prevent the checkbox from being checked if a condition is not met?
Or, how can I go about clearing the checkbox if user clicks Cancel in the alert?
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.
. 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.
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:
Click checkbox
Check if condition met
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.