Hello, I am working on a multipage app where one of the pages contains cards with a button for every user in the database, when the button is pressed, it opens a modal.
My question is since I have many users and don’t want to write a callback function for everyone’s modal, I am doing it in this way:
@app.callback(
[Output(m, 'is_open') for m in modals_id],
[Input(b, 'n_clicks') for b in buttons_id],
[Input(c, 'n_clicks') for c in close_modal_button],
[State(i, 'is_open') for i in modals_id])
def toggle_modal(n1, n2, is_open, *args):
trigger = callback_context.triggered[0]
button = "{}".format(trigger["prop_id"].split(".")[0])
if n1 or n2:
return not is_open
return is_open
When the cards are created, the ids for their buttons are saved in a list, using the name of the user.
I then use the trigger to get the name of the pressed button.
My question is: in the ‘if’ part, how can I specify that n1 and n2 and is_open are for this specific button id?
I just can’t get around it I tried button.n1, button.n2 and button.is_open ( hoping some mirracle to happen and to actually be valid code
)