Skip to content

Commit

Permalink
overriding gds data-prevent-double-click
Browse files Browse the repository at this point in the history
  • Loading branch information
CPrich905 committed Sep 28, 2023
1 parent 1a4d181 commit d0cb373
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions common/static/common/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import initCheckboxes from './checkboxes';
import initConditionalMeasureConditions from './conditionalMeasureConditions';
import initFilterDisabledToggleForComCode from './conditionalDisablingFilters'
import initOpenCloseAccordionSection from './openCloseAccordion';
import debounceButton from './buttonDebounce'
import tapDebounce from './buttonDebounce';
showHideCheckboxes();
// Initialise accessible-autocomplete components without a `name` attr in order
// to avoid the "dummy" autocomplete field being submitted as part of the form
Expand All @@ -28,4 +28,4 @@ initConditionalMeasureConditions();
initAutocompleteProgressiveEnhancement();
initFilterDisabledToggleForComCode();
initOpenCloseAccordionSection();
debounceButton();
tapDebounce();
33 changes: 22 additions & 11 deletions common/static/common/js/buttonDebounce.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
let button = document.getElementById('add-debounce')
let infoText = document.getElementById('add-debounce-inset-text')

const debounceButton = () => {
if (button) {
addEventListener('submit', function() {
button.disabled = true,
infoText.classList.remove('js-hidden')
})
const tapDebounce = function(event) {
console.log('b fires')
let DEBOUNCE_TIMEOUT_IN_SECONDS = 5;

if (this.tapDebounceFormSubmitTimer) {
console.log('c fires')
event.preventDefault();
button.disabled = true
return false
}


this.tapDebounceFormSubmitTimer = setTimeout(function () {
this.tapDebounceFormSubmitTimer = null;
}.bind(this), DEBOUNCE_TIMEOUT_IN_SECONDS * 1000);
};

document.querySelectorAll("[data-prevent-double-click").forEach(
(element) => {
element.addEventListener('click', tapDebounce);
}
}
)

export default debounceButton;
export default tapDebounce;
3 changes: 1 addition & 2 deletions measures/jinja2/measures/create-review.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,5 @@
{% endfor %}
{% endif %}
{% endcall %}
{{ govukInsetText({"text": "Your measures are being processed and the submit button is now disabled. You will be taken to a confirmation screen once the measures have been created.", "classes": "js-hidden", "attributes": {"id": "add-debounce-inset-text"},})}}
{{ govukButton({"text": "Create", "preventDoubleClick": true, "attributes": {"id": "add-debounce"},}) }}
{{ govukButton({"text": "Create", "preventDoubleClick": true}) }}
{% endblock %}

0 comments on commit d0cb373

Please sign in to comment.