Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Update & Delete? #123

Closed
dwasyl opened this issue Aug 21, 2020 · 3 comments
Closed

Async Update & Delete? #123

dwasyl opened this issue Aug 21, 2020 · 3 comments
Labels
Q&A Questions and answers

Comments

@dwasyl
Copy link

dwasyl commented Aug 21, 2020

Hi there,

This package is great and has really helped, but I was having some issues, trying to use it with async. Creating objects works gret and is no issue at all, however, by updating and deleting seem to have trouble. Delete works, but it reloads the page (so it's not async), and neither edit nor delete work after I've added a new object. I'm not entirely clear on how addModalFormFunction works when it would need to initialize both an update and delete button.

I've made some guesses based on the demo and the docs, but there's likely just some confusion about how it all works together.

So far I have this:

function addAttachmentModalForm() {
  $(".add-attachment").each(function () {
    $(this).modalForm({
      modalID: "#create-modal",
      formURL: "{% url 'citizen_attachment_add' form.instance.pk %}",
      asyncUpdate: true,
      asyncSettings: {
        closeOnSubmit: true,
        successMessage: "Added.",
        dataUrl: "LIST URL",
        dataElementId: "#attachments-container",
        dataKey: "list",
        addModalFormFunction: updateAttachmentModalForm,
      }
    });
  });
}
addAttachmentModalForm();

function updateAttachmentModalForm() {
  $(".update-attachment").each(function () {
    $(this).modalForm({
      formURL: $(this).data("form-url"),
      modalID: "#create-modal",
      asyncUpdate: true,
      asyncSettings: {
        closeOnSubmit: true,
        successMessage: "Updated.",
        dataUrl: "LIST URL",
        dataElementId: "#attachments-container",
        dataKey: "list",
        addModalFormFunction: updateAttachmentModalForm,
      }
    });
  });
}

function deleteAttachmentModalForm() {
  $(".delete-attachment").each(function () {
    $(this).modalForm({
      formURL: $(this).data("form-url"),
      modalID: "#std-modal",
      asyncUpdate: true,
      asyncSettings: {
        closeOnSubmit: true,
        successMessage: "Deleted.",
        dataUrl: "LIST URL",
        dataElementId: "#attachments-container",
        dataKey: "list",
        addModalFormFunction: updateAttachmentModalForm,
      }
    });
  });
}
deleteAttachmentModalForm();
@trco
Copy link
Owner

trco commented Aug 31, 2020

@dwasyl Package doesn't support async delete but this will change in near future. See #126.

@trco trco closed this as completed Aug 31, 2020
@trco trco added the Q&A Questions and answers label Aug 31, 2020
@dwasyl
Copy link
Author

dwasyl commented Aug 31, 2020

@trco perfect. After posting I'd realized delete might be completely separate. Glad it's getting added soon! That will really help. I suppose on the js side it just needs to reinitialize both buttons.

@Mergpijp
Copy link

Mergpijp commented Jan 12, 2021

@trco I looked in the code at async delete #126 because sync delete was not workng. It redirects to index with None behind the url. I am trying to find out what I am doing wrong. I put $(".bs-modal").each(function () { in _uploadedfiles_table.html so that the delete dialog works.
Update:
Never mind I solved this with JQuery/Ajax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Q&A Questions and answers
Projects
None yet
Development

No branches or pull requests

3 participants