django-bootstrap-modal-forms icon indicating copy to clipboard operation
django-bootstrap-modal-forms copied to clipboard

Create asynchronously without updating or rendering

Open JohannesPertl opened this issue 4 years ago • 4 comments
trafficstars

I'm implementing a feedback form modal. All I need is a simple form that creates a Feedback model without refreshing the page after submit.

It seems that asyncSettings always needs dataUrl, dataElementId and dataKey though, or else it doesn't create an object. Is it possible to simply create a model without those parameters?

JohannesPertl avatar Apr 12 '21 15:04 JohannesPertl

@JohannesPertl At the moment you can't do that, since as you stated specific parameters are needed. If I understand your case correctly you would like to create Feedback asynchronously, show success message but not update the existing page with given Feedback. Right?

trco avatar Apr 12 '21 17:04 trco

Yes exactly, thanks for the quick answer :) At the moment my workaround is to use the parameters with nonsense data like this:

function createFeedbackAsyncModalForm() {                     
    $(".create-feedback").modalForm({                         
        formURL: "{% url 'create_feedback' %}",               
        modalID: "#create-modal",                         
        asyncUpdate: true,                                    
        asyncSettings: {                                      
            closeOnSubmit: true,                              
            successMessage: asyncSuccessMessageCreate,        
            dataUrl: "feedback/",                             
            dataElementId: "nonsense",                        
            dataKey: "nonsense",                              
            addModalFormFunction: createFeedbackAsyncModalForm
        }                                                     
    });                                                       
}                                                             
createFeedbackAsyncModalForm();                               

and in the views.py

def feedback(request):
    if request.method == 'GET':
        return HttpResponse(200)

It would be cleaner if those workarounds were not needed

JohannesPertl avatar Apr 12 '21 18:04 JohannesPertl

@JohannesPertl I'll do my best to sort this out as soon as possible.

trco avatar Apr 16 '21 19:04 trco

I was hoping to have this kind of implementation in Asyn for some of my models. Where I want to create a model without giving any other parameter except : SuccessMessage.

So that way it just close the Modal and show a success message if the model has been created

Thank you Uros.

infosrabah avatar Apr 18 '21 14:04 infosrabah