0

I have a table of users and one table data is a button that opens up a modal, I am including the modal in the tamplate with the include tag. How do I pass the user from the row in which the button was clicked to the include tag?

{% for user in users %}
<tr>
 <td>
   <button class="btn btn-lg device-select-button">
          <span>Select Device</span>
   </button>
 </td>
</tr>
{% endfor %}

{% include 'app/admin/users/device_select_modal.html' user={{add here user}} %}

In other implementation I have generated a modal for each row, and it works but slow, So I want to reimplement that

1
  • I think you'll need JavaScript to do that. AFAIk the template is built only once when you load the page, there's no way to tell it to wait for the user to click. Also see this question. Commented Jun 22, 2021 at 10:26

1 Answer 1

1

One approach might be to store the required data you want to pass to the modal as html data attribute

<button data-id={{ user.id }} data-name="{{ user.name }}" class="btn btn-lg device-select-button">

And in your implementation of the modal you can pass data using the onclick attribute of the button with some javascript.

<button onclick="yourFunctionThatOpensModal(this.getAttribute('data-name'), this.getAttribute('data-id'))"  data-id={{ user.id }} data-name="{{ user.name }}" class="btn btn-lg device-select-button">
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.