You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Set ``asyncUpdate`` and ``asyncSettings`` settings to create or update objects without page redirection to ``successUrl`` and define whether a modal should close or stay opened after form submission. See comments in example below and paragraph **modalForm options** for explanation of ``asyncSettings``.
"$('.alert').fadeTo(2000, 500).slideUp(500, function () {$('.alert').slideUp(500).remove();});",
260
+
"<\/script>"
261
+
].join();
262
+
263
+
# asyncSettings.addModalFormFunction
264
+
functionupdateBookModalForm() {
265
+
$(".update-book").each(function () {
266
+
$(this).modalForm({
267
+
formURL:$(this).data("form-url"),
268
+
asyncUpdate:true,
269
+
asyncSettings: {
270
+
closeOnSubmit:false,
271
+
successMessage: asyncSuccessMessage
272
+
dataUrl:"books/",
273
+
dataElementId:"#books-table",
274
+
dataKey:"table",
275
+
addModalFormFunction: updateBookModalForm
276
+
}
277
+
});
278
+
});
279
+
}
280
+
updateBookModalForm();
281
+
282
+
...
283
+
});
284
+
</script>
285
+
286
+
.. code-block:: python
287
+
288
+
urls.py
289
+
290
+
from django.urls import path
291
+
from . import views
292
+
293
+
urlpatterns = [
294
+
...
295
+
# asyncSettings.dataUrl
296
+
path('books/', views.books, name='books'),
297
+
...
298
+
]
299
+
300
+
.. code-block:: python
301
+
302
+
views.py
303
+
304
+
from django.http import JsonResponse
305
+
from django.template.loader import render_to_string
306
+
from .models import Book
307
+
308
+
defbooks(request):
309
+
data =dict()
310
+
if request.method =='GET':
311
+
books = Book.objects.all()
312
+
# asyncSettings.dataKey = 'table'
313
+
data['table'] = render_to_string(
314
+
'_books_table.html',
315
+
{'books': books},
316
+
request=request
317
+
)
318
+
return JsonResponse(data)
319
+
215
320
modalForm options
216
321
=================
217
322
@@ -233,6 +338,27 @@ errorClass
233
338
submitBtn
234
339
Sets the custom class for the button triggering form submission in modal. ``Default: ".submit-btn"``
235
340
341
+
asyncUpdate
342
+
Sets asynchronous content update after form submission. ``Default: false``
343
+
344
+
asyncSettings.closeOnSubmit
345
+
Sets whether modal closes or not after form submission. ``Default: false``
346
+
347
+
asyncSettings.successMessage
348
+
Sets successMessage shown after succesful for submission. Should be set to string defining message element. See ``asyncSuccessMessage`` example above. ``Default: null``
349
+
350
+
asyncSettings.dataUrl
351
+
Sets url of the view returning new queryset = all of the objects plus newly created or updated one after asynchronous update. ``Default: null``
352
+
353
+
asyncSettings.dataElementId
354
+
Sets the ``id`` of the element which renders asynchronously updated queryset. ``Default: null``
355
+
356
+
asyncSettings.dataKey
357
+
Sets the key containing asynchronously updated queryset in the data dictionary returned from the view providing updated queryset. ``Default: null``
358
+
359
+
asyncSettings.addModalFormFunction
360
+
Sets the method needed for reinstantiation of event listeners on button after asynchronous update. ``Default: false``
0 commit comments