Skip to content

Commit

Permalink
fix: add contraint to click only once on create buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
juggler31 committed Jul 25, 2024
1 parent e7ddc35 commit 3ffd737
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ CHANGELOG
8.9.2+dev (XXXX-XX-XX)
-----------------------

**Bug fixes**

- Add contraint to click only once on create buttons


8.9.2 (2024-07-15)
Expand Down
7 changes: 3 additions & 4 deletions mapentity/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ class SubmitButton(HTML):

def __init__(self, div_id, label):
content = ("""
<a id="{0}" class="btn btn-success"
onclick="javascript:$(this).parents('form').submit();">
<button type="submit" id="{0}" class="btn btn-success">
<i class="bi bi-check-circle-fill"></i> {1}
</a>""".format(div_id, label))
</button>""".format(div_id, label))
super().__init__(content)


Expand Down Expand Up @@ -226,7 +225,7 @@ def _init_layout(self):

# Main form layout
self.helper.help_text_inline = True
self.helper.form_class = 'form-horizontal'
self.helper.form_class = 'form-horizontal mapentity-form'
self.helper.form_style = "default"
self.helper.label_class = 'col-md-3'
self.helper.field_class = 'controls col-md-9'
Expand Down
15 changes: 15 additions & 0 deletions mapentity/static/mapentity/mapentity.forms.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
if (!window.MapEntity) window.MapEntity = {};

// Disable button if submit event on form
Array.from(document.getElementsByClassName("mapentity-form")).forEach(function (formElement) {

var submitButtonElement = formElement.querySelector("button[type=submit]")
submitButtonElement.removeAttribute("disabled")

formElement.addEventListener('submit', function () {
submitButtonElement.setAttribute("disabled", true)
// setTimeout in case of browser back page button click, to remove the persistent disabled attribute on button.
setTimeout(function () {
submitButtonElement.removeAttribute("disabled")
}, 2000)
}, false)
});

MapEntity.GeometryField = L.GeometryField.extend({

initialize: function () {
Expand Down

0 comments on commit 3ffd737

Please sign in to comment.