-
Notifications
You must be signed in to change notification settings - Fork 142
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
Double post when submitting modal form #230
Comments
This bug ruined my whole week! |
I confirm this issue is not resolved from last released package version (3.0.4). Also the workaround from @amir4v with patched Javascript is not enough (maybe there is some view patch to apply also?), it changes some behavior but it does not fix double POST request. |
Hey guys! It would be optimal to have working=non-working example, this way I could check this out faster, maybe even during next weekend. Please check https://github.com/trco/django-bootstrap-modal-forms#opening-an-issue. My first impression is that we should add an option where developer would be able to define if he wants to skip ajax form validation when using BSModalForm and maybe even BSModalModelForm. I believe you hit the case I never thought about. Of course the override of some predefined methods could also be the answer. |
I've solved the issue (at least for now) with this Using:
|
Can confirm. Implemented in 08/2022 the same solution and added a comment for future me on why I did this. django-bootstrap-modal even provides an own implementation of from bootstrap_modal_forms.mixins import is_ajax
...
if request.method == "POST":
if self.is_valid():
if not is_ajax(request.META):
# Modal forms send one POST for checking on data validity. This can be used to return possible errors
# on the form. A second POST (if no errors occured) is sent afterwards and needs to process the
# saving/commiting of the data to the database. is_ajax() performs this check. The first request is
# an ajax call, the second is a regular form POST.
self.save()
messages.success(
request,
msg_success
)
return HttpResponseRedirect(redirect_url)
else:
context = {
"form": self,
}
context = BaseContext(request, context).context
return render(request, template, context) |
Hi,
I have a
BSModalFormView
with aBSModalForm
for the form.When I submit the form it double posts.
Since I'm deleting the initial result, when it calls the post the second time returns 404.
After a bit of research I've found Stack overflow post which seems to be the same.
The top answer says the package was updated and that fixes the problem, however it is still doing it for me.
When I've tried to print the
self.request.is_ajax()
I get the'WSGIRequest' object has no attribute 'is_ajax'
which brought me to this call was depreciated in Django 3.1.Which from the depreciation notes lead me to:
The check for the header will not save the form on the first call only on the second.
This doesn't seem a very pythonic answer to me.
The text was updated successfully, but these errors were encountered: