Skip to content

Commit e272a8e

Browse files
committed
change button type to submit
1 parent 280e128 commit e272a8e

File tree

8 files changed

+49
-39
lines changed

8 files changed

+49
-39
lines changed

examples/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BookFilterForm(BSModalForm):
1111
type = forms.ChoiceField(choices=Book.BOOK_TYPES)
1212

1313
class Meta:
14-
fields = ['type', 'clear']
14+
fields = ['type']
1515

1616

1717
class BookModelForm(BSModalModelForm):

examples/templates/_books_table.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
<td class="text-center">{{ book.price }}</td>
2424
<td class="text-center">
2525
<!-- Read book buttons -->
26-
<button type="button" class="bs-modal read-book btn btn-sm btn-primary" data-form-url="{% url 'read_book' book.pk %}">
26+
<button type="button" class="read-book btn btn-sm btn-primary" data-form-url="{% url 'read_book' book.pk %}">
2727
<span class="fa fa-eye"></span>
2828
</button>
2929
<!-- Update book buttons -->
3030
<button type="button" class="update-book btn btn-sm btn-primary" data-form-url="{% url 'update_book' book.pk %}">
3131
<span class="fa fa-pencil"></span>
3232
</button>
3333
<!-- Delete book buttons -->
34-
<button type="button" class="bs-modal delete-book btn btn-sm btn-danger" data-form-url="{% url 'delete_book' book.pk %}">
34+
<button type="button" class="delete-book btn btn-sm btn-danger" data-form-url="{% url 'delete_book' book.pk %}">
3535
<span class="fa fa-trash"></span>
3636
</button>
3737
</td>

examples/templates/examples/create_book.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h3 class="modal-title">Create Book</h3>
3232
</div>
3333

3434
<div class="modal-footer">
35-
<button type="button" class="submit-btn btn btn-primary">Create</button>
35+
<button type="submit" class="btn btn-primary">Create</button>
3636
</div>
3737

3838
</form>

examples/templates/examples/filter_book.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ <h3 class="modal-title">Filter Books</h3>
3434

3535

3636
<div class="modal-footer">
37-
<input type="submit" class="btn btn-primary" name="clear" value="Clear"/>
38-
<button type="button" class="submit-btn btn btn-primary">Filter</button>
37+
<button type="submit" class="btn btn-primary">Filter</button>
3938
</div>
4039

4140
</form>

examples/templates/examples/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h3 class="modal-title">Log in</h3>
3232
</div>
3333

3434
<div class="modal-footer">
35-
<button type="button" class="submit-btn btn btn-primary" formnovalidate="formnovalidate">Log in</button>
35+
<button type="submit" class="btn btn-primary" formnovalidate="formnovalidate">Log in</button>
3636
</div>
3737

3838
</form>

examples/templates/examples/signup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h3 class="modal-title">Sign up</h3>
3232
</div>
3333

3434
<div class="modal-footer">
35-
<button type="button" class="submit-btn btn btn-primary" formnovalidate="formnovalidate">Sign up</button>
35+
<button type="submit" class="btn btn-primary" formnovalidate="formnovalidate">Sign up</button>
3636
</div>
3737

3838
</form>

examples/templates/examples/update_book.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h3 class="modal-title">Update Book</h3>
3232
</div>
3333

3434
<div class="modal-footer">
35-
<button type="button" class="submit-btn btn btn-primary">Update</button>
35+
<button type="submit" class="btn btn-primary">Update</button>
3636
</div>
3737

3838
</form>

examples/templates/index.html

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ <h4>
4848
<button id="create-book-async" class="btn btn-primary" type="button" name="button">
4949
<span class="fa fa-plus mr-2"></span>Create book - Asynchronous
5050
</button>
51-
<button id="filter-book" class="bs-modal btn btn-primary" type="button" name="button" data-form-url="{% url 'filter_book' %}">
51+
<button id="filter-book" class="filter-book btn btn-primary" type="button" name="button" data-form-url="{% url 'filter_book' %}">
5252
<span class="fa fa-filter mr-2"></span>Filter books
5353
</button>
5454
</div>
5555
<div class="col-12 mb-3">
56+
{% if 'type' in request.GET %}
57+
<p class="filtered-books">Filtered books.</p>
58+
{% endif %}
5659
{% if books %}
5760
{% include "_books_table.html" %}
5861
{% else %}
@@ -69,24 +72,17 @@ <h4>
6972
{% block extrascripts %}
7073
<script type="text/javascript">
7174
$(function () {
72-
// Log in & Sign up buttons
73-
// The formURL is given explicitly
75+
// Login
7476
$("#login-btn").modalForm({
7577
formURL: "{% url 'login' %}"
7678
});
7779

80+
// Signup
7881
$("#signup-btn").modalForm({
7982
formURL: "{% url 'signup' %}"
8083
});
8184

82-
// Create book button opens modal with id="create-modal"
83-
/*
84-
$("#create-book").modalForm({
85-
formURL: "{% url 'create_book' %}",
86-
modalID: "#create-modal"
87-
});
88-
*/
89-
85+
// Create book synchronous
9086
function createBookSyncModalForm() {
9187
$("#create-book-sync").modalForm({
9288
formURL: "{% url 'create_book' %}",
@@ -95,6 +91,8 @@ <h4>
9591
}
9692
createBookSyncModalForm();
9793

94+
// Create book asynchronous button
95+
// message
9896
var asyncSuccessMessageCreate = [
9997
"<div ",
10098
"style='position:fixed;top:0;z-index:10000;width:100%;border-radius:0;' ",
@@ -109,6 +107,26 @@ <h4>
109107
"<\/script>"
110108
].join("");
111109

110+
// modal form
111+
function createBookAsyncModalForm() {
112+
$("#create-book-async").modalForm({
113+
formURL: "{% url 'create_book' %}",
114+
modalID: "#create-modal",
115+
asyncUpdate: true,
116+
asyncSettings: {
117+
closeOnSubmit: true,
118+
successMessage: asyncSuccessMessageCreate,
119+
dataUrl: "books/",
120+
dataElementId: "#books-table",
121+
dataKey: "table",
122+
addModalFormFunction: updateBookModalForm
123+
}
124+
});
125+
}
126+
createBookAsyncModalForm();
127+
128+
// Update book asynchronous button
129+
// message
112130
var asyncSuccessMessageUpdate = [
113131
"<div ",
114132
"style='position:fixed;top:0;z-index:10000;width:100%;border-radius:0;' ",
@@ -123,6 +141,7 @@ <h4>
123141
"<\/script>"
124142
].join("");
125143

144+
// modal form
126145
function updateBookModalForm() {
127146
$(".update-book").each(function () {
128147
$(this).modalForm({
@@ -141,26 +160,18 @@ <h4>
141160
}
142161
updateBookModalForm();
143162

144-
function createBookAsyncModalForm() {
145-
$("#create-book-async").modalForm({
146-
formURL: "{% url 'create_book' %}",
147-
modalID: "#create-modal",
148-
asyncUpdate: true,
149-
asyncSettings: {
150-
closeOnSubmit: true,
151-
successMessage: asyncSuccessMessageCreate,
152-
dataUrl: "books/",
153-
dataElementId: "#books-table",
154-
dataKey: "table",
155-
addModalFormFunction: updateBookModalForm
156-
}
157-
});
158-
}
159-
createBookAsyncModalForm();
163+
// Delete book buttons - formURL is retrieved from the data of the element
164+
$(".delete-book").each(function () {
165+
$(this).modalForm({formURL: $(this).data("form-url"), isDeleteForm: true});
166+
});
167+
168+
// Read book buttons
169+
$(".read-book").each(function () {
170+
$(this).modalForm({formURL: $(this).data("form-url")});
171+
});
160172

161-
// Read and Delete book buttons open modal with id="modal"
162-
// The formURL is retrieved from the data of the element
163-
$(".bs-modal").each(function () {
173+
// Filter books button
174+
$("#filter-book").each(function () {
164175
$(this).modalForm({formURL: $(this).data("form-url")});
165176
});
166177

0 commit comments

Comments
 (0)