title: Jquery Modal Confirmation on Django form submit for deletion of object
body: <p>I am using Django with Crispy forms and am also using the Shopify Embedded Apps SDK. I am trying to have a modal window appear to let the user confirm that they want to delete an object.</p>
  
  <p>My code is attached so far. I have the modal window appearing with the following code, however, the form is not submitted (and the object is not deleted) after the user selects 'delete' on the modal window:
  <a href="https://i.stack.imgur.com/BJlxD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BJlxD.png" alt="enter image description here"></a></p>
  
  <p><strong>It just closed the modal and nothing happens.</strong></p>
  
  <p>I have tried various methods from around the net, but haven't had any luck.</p>
  
  <p><strong>form.py</strong></p>
  
  <pre><code>class MyForm(forms.ModelForm):
      def __init__(self, *args, **kwargs):
          super(MyForm, self).__init__(*args, **kwargs)
  
          self.helper = FormHelper(self)
  
          self.helper.form_id = 'edit_form'
  
          self.helper.layout = Layout(        
              [... some input fields...]
          )
  
          # Add delete button
          self.helper.layout.append(Button('delete', 'delete'))
  
          # Normal submit button
          self.helper.layout.append(Submit('save', 'save'))
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>@login_required
  def edit_object(request, *args, **kwargs):
      # Form handling logic
       with request.user.session:
           object = get_object_or_404(models.Object, pk=kwargs['object_id'], ...)
  
          if request.method == "POST":
              form = forms.MyForm(request.POST, request=request, instance=object)
  
              if not form.is_valid():
                 [... do some stuff ...]
  
              if form.is_valid():
  
                  # If the save button is pressed
                  if request.POST.get('save'):
                      [... do some stuff to save and redirect to url of my choice ...]
  
                  # If the delete button is pressed &lt;&lt;&lt;&lt; The Modal should appear prior to this
                  if request.POST.get('delete'):
                      [... delete to object and redirect to url of my choice ... ]
          else:
              form = forms.MyForm(request=request, instance=supplier)
  
          return render(request, 'template.html', {'form': form})
  </code></pre>
  
  <p><strong>template.html using Shopify Embedded App SDK:</strong></p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
          [...]
          ShopifyApp.ready(function() {
              ShopifyApp.Bar.initialize({});
  
              $("#button-id-delete").click(function(ev){
                  ShopifyApp.Modal.confirm({message: "Are you sure you want to delete?"}, function(result){
                      if(!result){
                          result.preventDefault();
                      }
                      else {
                          alert("Contine");
                          $("form#edit_form").submit();
                      }
                  });
              });
          });
      &lt;/script&gt;
  
  &lt;form enctype="multipart/form-data" method="post"&gt;
      {% crispy form %}
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>rendered html</strong></p>
  
  <pre><code>&lt;form enctype="multipart/form-data" method="post"&gt;
      &lt;form  id="edit_form" method="post" &gt; &lt;input type='hidden' name='csrfmiddlewaretoken' value='.......' /&gt; 
         [.... various input fields .....]
         &lt;input type="button"
            name="delete"
            value="delete"
            class="btn destroy btn"
            id="button-id-delete"
            /&gt;
         &lt;input type="submit"
            name="save"
            value="save"
            class="btn btn-primary"
            id="submit-id-save"
            /&gt;
      &lt;/form&gt;
  &lt;/form&gt;
  </code></pre>