Skip to content

Commit 1058c70

Browse files
committed
update README.rst
1 parent 4522417 commit 1058c70

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

README.rst

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ Define BookModelForm and inherit built-in form ``BSModalModelForm``.
9292
Define form's html and save it as Django template.
9393

9494
- Bootstrap 4 modal elements are used in this example.
95-
- Button triggering the submission should have type attribute set to ``"button"`` and not ``"submit"``.
96-
- Add ``class="submit-btn"`` or custom ``submitBtn`` class (see paragraph **Options**) to this button.
9795
- Form will POST to ``formURL`` defined in #6.
9896
- Add ``class="invalid"`` or custom ``errorClass`` (see paragraph **Options**) to the elements that wrap the fields.
9997
- ``class="invalid"`` acts as a flag for the fields having errors after the form has been POSTed.
@@ -126,7 +124,7 @@ Define form's html and save it as Django template.
126124

127125
<div class="modal-footer">
128126
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
129-
<button type="button" class="submit-btn btn btn-primary">Create</button>
127+
<button type="submit" class="btn btn-primary">Create</button>
130128
</div>
131129

132130
</form>
@@ -332,12 +330,12 @@ modalForm
332330
formURL
333331
Sets the url of the form's view and html. ``Default: null``
334332

333+
isDeleteForm
334+
Defines if form is used for deletion. Should be set to ``true`` for deletion forms. ``Default: false``
335+
335336
errorClass
336337
Sets the custom class for the form fields having errors. ``Default: ".invalid"``
337338

338-
submitBtn
339-
Sets the custom class for the button triggering form submission in modal. ``Default: ".submit-btn"``
340-
341339
asyncUpdate
342340
Sets asynchronous content update after form submission. ``Default: false``
343341

@@ -351,7 +349,7 @@ asyncSettings.dataUrl
351349
Sets url of the view returning new queryset = all of the objects plus newly created or updated one after asynchronous update. ``Default: null``
352350

353351
asyncSettings.dataElementId
354-
Sets the ``id`` of the element which renders asynchronously updated queryset. ``Default: null``
352+
Sets the ``id`` of the element which rerenders asynchronously updated queryset. ``Default: null``
355353

356354
asyncSettings.dataKey
357355
Sets the key containing asynchronously updated queryset in the data dictionary returned from the view providing updated queryset. ``Default: null``
@@ -369,8 +367,8 @@ modalForm default settings object and it's structure
369367
modalContent: ".modal-content",
370368
modalForm: ".modal-content form",
371369
formURL: null,
370+
isDeleteForm: false,
372371
errorClass: ".invalid",
373-
submitBtn: ".submit-btn",
374372
asyncUpdate: false,
375373
asyncSettings: {
376374
closeOnSubmit: false,
@@ -509,7 +507,7 @@ For explanation how all the parts of the code work together see paragraph **Usag
509507
</div>
510508

511509
<div class="modal-footer">
512-
<button type="button" class="submit-btn btn btn-primary">Sign up</button>
510+
<button type="submit" class="btn btn-primary">Sign up</button>
513511
</div>
514512

515513
</form>
@@ -627,7 +625,7 @@ You can also set the custom login redirection by:
627625
</div>
628626

629627
<div class="modal-footer">
630-
<button type="button" class="submit-btn btn btn-primary">Log in</button>
628+
<button type="submit" class="btn btn-primary">Log in</button>
631629
</div>
632630

633631
</form>
@@ -735,7 +733,7 @@ For explanation how all the parts of the code work together see paragraph **Usag
735733
</div>
736734

737735
<div class="modal-footer">
738-
<button type="button" class="submit-btn btn btn-primary">Create</button>
736+
<button type="submit" class="btn btn-primary">Create</button>
739737
</div>
740738

741739
</form>
@@ -777,7 +775,7 @@ For explanation how all the parts of the code work together see paragraph **Usag
777775
</div>
778776

779777
<div class="modal-footer">
780-
<button type="button" class="submit-btn btn btn-primary">Update</button>
778+
<button type="submit" class="btn btn-primary">Update</button>
781779
</div>
782780

783781
</form>
@@ -940,15 +938,17 @@ For explanation how all the parts of the code work together see paragraph **Usag
940938
<script type="text/javascript">
941939
$(function () {
942940
943-
// Update, Read and Delete book buttons open modal with id="modal" (default)
944-
// The formURL is retrieved from the data of the element
945-
$(".bs-modal").each(function () {
946-
$(this).modalForm({
947-
formURL: $(this).data('form-url')
948-
});
941+
// Read book buttons
942+
$(".read-book").each(function () {
943+
$(this).modalForm({formURL: $(this).data("form-url")});
949944
});
950945
951-
// Create book button opens form in modal with id="create-modal"
946+
// Delete book buttons - formURL is retrieved from the data of the element
947+
$(".delete-book").each(function () {
948+
$(this).modalForm({formURL: $(this).data("form-url"), isDeleteForm: true});
949+
});
950+
951+
// Create book button opens form in modal with id="create-modal"
952952
$("#create-book").modalForm({
953953
formURL: "{% url 'create_book' %}",
954954
modalID: "#create-modal"
@@ -976,7 +976,7 @@ For explanation how all the parts of the code work together see paragraph **Usag
976976
type = forms.ChoiceField(choices=Book.BOOK_TYPES)
977977
978978
class Meta:
979-
fields = ['type', 'clear']
979+
fields = ['type']
980980
981981
.. code-block:: html
982982

@@ -1015,8 +1015,7 @@ For explanation how all the parts of the code work together see paragraph **Usag
10151015
</div>
10161016

10171017
<div class="modal-footer">
1018-
<input type="submit" class="btn btn-primary" name="clear" value="Clear"/>
1019-
<button type="button" class="submit-btn btn btn-primary">Filter</button>
1018+
<button type="submit" class="btn btn-primary">Filter</button>
10201019
</div>
10211020

10221021
</form>
@@ -1030,11 +1029,7 @@ For explanation how all the parts of the code work together see paragraph **Usag
10301029
form_class = BookFilterForm
10311030
10321031
def form_valid(self, form):
1033-
if 'clear' in self.request.POST:
1034-
self.filter = ''
1035-
else:
1036-
self.filter = '?type=' + form.cleaned_data['type']
1037-
1032+
self.filter = '?type=' + form.cleaned_data['type']
10381033
response = super().form_valid(form)
10391034
return response
10401035
@@ -1058,15 +1053,15 @@ For explanation how all the parts of the code work together see paragraph **Usag
10581053
index.html
10591054

10601055
...
1061-
<button id="filter-book" class="bs-modal btn btn-primary" type="button" name="button" data-form-url="{% url 'filter_book' %}">
1056+
<button id="filter-book" class="filter-book btn btn-primary" type="button" name="button" data-form-url="{% url 'filter_book' %}">
10621057
<span class="fa fa-filter mr-2"></span>Filter books
10631058
</button>
10641059
...
10651060

10661061
<script type="text/javascript">
10671062
$(function () {
10681063
...
1069-
$(".bs-modal").each(function () {
1064+
$("#filter-book").each(function () {
10701065
$(this).modalForm({formURL: $(this).data('form-url')});
10711066
});
10721067
...

0 commit comments

Comments
 (0)