onkar
onkar

Reputation: 4547

Set dynamic Value for Modal Action Form

I need to set dynamic value for Modal popup.

This is my modal

 <!-- Modal -->
  <div class="modal fade" id="popUpModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">"this is the value {{ cra }}"</h4>
        </div>
        <form class="modal-form" id="docsForm" action="{% url 'contact_delete' pk=contact.id %}"  method="post" enctype="multipart/form-data">
<input type="file" name="upload" />
<input type="hidden" name="brandcode" value=this.id />
<input type="submit" /></form>
        <div class="modal-footer">

        </div>
      </div>

    </div>
  </div>

This is what I am trying

<script>
    $('#popUpModal').on('show.bs.modal', function(e) {

      var $modal = $(this),
        esseyId = e.relatedTarget.id;
        $modal.find('.modal-form').html(esseyId);

    })
  </script>

based on the record I want value like

contact/delete/1
contact/delete/2
....

Update 1

          <a id="{{ contact.id }}" type="button" data-target="#popUpModal" class="btn btn-box-tool" data-toggle="modal" data-original-title="{% trans 'Update Doc' %}">

Upvotes: 0

Views: 2079

Answers (1)

onkar
onkar

Reputation: 4547

This is the way I am getting the expected response

<script type="text/javascript">
$('#popUpModal').on('show.bs.modal', function (event) {
  var button = $(event.relatedTarget) // Button that triggered the modal
  var id= button.data('id') // Extract info from data-* attributes

  var modal = $(this)
  console.log(id)
  $("#docsForm").attr("action", "/contact_delete/" + id+"/");
})
 </script>

Upvotes: 4

Related Questions