How do I change the state of a single button in a table with collection items?

Hi,

Couldn’t find a solution myself… I have a table with a header. The header contains only one collection item and a button. In the table cell is another table with collection items. I want to create a animation to give visual feedback, when the button is clicked. I created an “Active” state, bound it to a variable and start the animation with a workflow and a onClick trigger. It works fine so far, but if I click the button, all buttons are animated, not only the clicked one. How can I make sure, that only the clicked button gets triggered?

Thanks in advance,
Stefan

Hi Stefan!

We might need to go back and forth a little here but it might be a good idea to bind the state of the button to a field in your backend (Airtable, Xano, Supabase, or whatever you are using).

The reason I mention this is assuming that once your user leave and then comes back to this page, the button should still reflect the “Active” state. Bind this state of your button to a status in your backend could solve for that.

To do this, you will create a Workflow on the click of the button to “Update” for whichever backend you are using. WeWeb should then prompt you to define which record you are looking to update, and therefore allowing you to properly change the status in the backend. This allows you to have a more successful “state” of your button.

Let me know if that doesn’t help!

1 Like

Hi @chadsmithclt,

Thank you for taking the time. I use Xano and I’ll have a look to at this. The way I want it to work is:

  1. User clicks the button (it says “Create invoice”)
  2. Button animation play as feedback that it was clicked
  3. A webhook request is send to create the invoice in the backend and mark the records as billed
  4. if the result is success, the text of the button changes and the whole table element disappaers

If the user revisit the page again, this dataset won’t show up again since it only show unbilled entries.

Since the hover state works fine for the actually hovered button, I thought I could get the same result with an active state. Instead is animates all buttons in the table :grinning:

Hi @stefank
I think I understand your use case, 100% possible without a doubt.

I’ll get a Loom out to you today on this thread showing how to do it :slight_smile:

1 Like

the key here is that you can use a boolean variable to trigger the action of a single button, but for a list of buttons you also need to know which button in the list has been clicked.
You can do this by using an object. It’s the same principle of keeping track of inputs inside a colletion list. Have a look at this post and this post

1 Like

I was going to record the same :slight_smile: hope this helps, if not let us know!

Thanks guys, I’ll check this out and update the post with the result :+1:t3:

@dorilama @chadsmithclt

Sorry, I forgot to give feedback. I’ve used your approach and it worked perfectly. Thanks for your time and help.

1 Like

That’s great, thanks for the update :slight_smile: