Comments (5)
I've solved the issue (at least for now) with this is_ajax
replacement based on https://stackoverflow.com/a/60856647/3642184
Using:
Django 3.2.23 (LTS)
Djano Bootstrap Modal Forms 3.0.4
class TestimonialFormView(BSModalFormView):
...
def form_valid(self, form):
...
if not self.request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest':
DO_STUFF_ONLY_ONCE_HERE
response = super().form_valid(form)
return response
from django-bootstrap-modal-forms.
This bug ruined my whole week!
I fixed it, you can use this file in my repo:
https://github.com/amir4v/dev/blob/main/jquery-django-bootstrap-modal-forms.js
from django-bootstrap-modal-forms.
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.
from django-bootstrap-modal-forms.
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.
from django-bootstrap-modal-forms.
I've solved the issue (at least for now) with this
is_ajax
replacement based on https://stackoverflow.com/a/60856647/3642184Using: Django 3.2.23 (LTS) Djano Bootstrap Modal Forms 3.0.4
class TestimonialFormView(BSModalFormView): ... def form_valid(self, form): ... if not self.request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest': DO_STUFF_ONLY_ONCE_HERE response = super().form_valid(form) return response
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 is_ajax
(which basically is @fergbrain 's solution), which can be used (https://github.com/trco/django-bootstrap-modal-forms/blob/master/bootstrap_modal_forms/mixins.py#L104-L105).
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)
from django-bootstrap-modal-forms.
Related Issues (20)
- missing "database" folder
- Allow to send extra parameters in the POST request.
- Multiple submit buttons in modal
- Maintenance of the project HOT 9
- Automate JS Minify Process
- How to make a nested modal
- Undesired GET request when using a BSModalCreateView HOT 4
- Incorrect errorClass in documentation HOT 1
- Generic views don't respond to get_success_url() since version 3.0.0 HOT 5
- Delete view success message is shown although object not deleted HOT 1
- form validation object already exist error does not shown in modal after modal form submissin with crispy form within modal HOT 3
- Django Internal server error - widget_tweaks failed to parse render_field HOT 1
- Checkbox does not render correctly. HOT 3
- btnSubmit fails detection after html minification
- Restrict users from directly accessing the form url HOT 1
- How to remove Click listener HOT 1
- Open a new modal with the current modal form's results
- Event listeners disappear after the form is invalid. HOT 1
- FormValidationMixin shadows setting of self.object (defined in BaseCreateView)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-bootstrap-modal-forms.