Checkbox value live sync with database

I have a card collection view component that contains a checkbox.
This checkbox is synced with the column "BeingPaid" out of the table "Userss".
However, I want to change the checkbox at my page and at the same time the database.
In SQL queries I can use {{PaymentOverview.SelectedItem.BeingPaid}}, but of course that is the current data and not the just changed check mark.
I know you have temporary states and all, but I still don't know how to combine that with my case.
Anybody tips and tricks?

I have used queries like this:

UPDATE "Userss"
SET "BeingPaid" = {{GroupPaymentOverview.selectedItem.BeingPaid}}
WHERE "id" = {{ GroupPaymentOverview.selectedItem.UserID }};


UPDATE "Userss"
SET "BeingPaid" = (CASE WHEN {{GroupPaymentOverview.selectedItem.BeingPaid[0]}} = 1 THEN true ELSE false END)
WHERE "id" = {{ GroupPaymentOverview.selectedItem.UserID }};

After this query I refresh the query "AllIndividualBills" as seen in the picture in the top right corner.

Hi @Luc,

Great question!

You should be able to use the .suffixValueByIndex property to see the new checkbox values

Does this property seem like it would resolve your question? It seems like you could reference it directly instead of implementing temporary state

1 Like

Thank you for your help, but I am still stuck with it :frowning:
I copied what you did, but in my occasion the database does not change when I check or uncheck a checkbox.

Hi @Luc, can we see an updated screenshot of your database write query?

Here's a more complete example that updates my database. Keep in mind that this will only work if triggered from the checkbox event handler. If I attempt to run this query from the query editor "Run" button, index won't be defined.

Please also note that you need to re-trigger the get request on success:

1 Like

Yes this solved my problem.
Many thanks!!!

1 Like