From 76f73eebea0fa875487611cf9e01d8167e84a142 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 18 Feb 2017 15:53:48 -0500 Subject: Upload files button stay disabled when there are other submit buttons on the same page --- assets/js/components/submit-buttons.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'assets/js/components') diff --git a/assets/js/components/submit-buttons.js b/assets/js/components/submit-buttons.js index 2745841a..9e8ec1ca 100644 --- a/assets/js/components/submit-buttons.js +++ b/assets/js/components/submit-buttons.js @@ -3,10 +3,11 @@ KB.component('submit-buttons', function (containerElement, options) { var isDisabled = options.disabled || false; var submitLabel = options.submitLabel; var formActionElement = null; + var submitButtonElement = null; function onSubmit() { isLoading = true; - KB.find('#modal-submit-button').replace(buildButton()); + replaceButton(); KB.trigger('modal.submit'); } @@ -16,19 +17,19 @@ KB.component('submit-buttons', function (containerElement, options) { function onStop() { isLoading = false; - KB.find('#modal-submit-button').replace(buildButton()); + replaceButton(); } function onDisable() { isLoading = false; isDisabled = true; - KB.find('#modal-submit-button').replace(buildButton()); + replaceButton(); } function onEnable() { isLoading = false; isDisabled = false; - KB.find('#modal-submit-button').replace(buildButton()); + replaceButton(); } function onHide() { @@ -37,12 +38,11 @@ KB.component('submit-buttons', function (containerElement, options) { function onUpdateSubmitLabel(eventData) { submitLabel = eventData.submitLabel; - KB.find('#modal-submit-button').replace(buildButton()); + replaceButton(); } function buildButton() { var button = KB.dom('button') - .attr('id', 'modal-submit-button') .attr('type', 'submit') .attr('class', 'btn btn-' + (options.color || 'blue')); @@ -71,6 +71,12 @@ KB.component('submit-buttons', function (containerElement, options) { .build(); } + function replaceButton() { + var buttonElement = buildButton(); + KB.dom(submitButtonElement).replace(buttonElement); + submitButtonElement = buttonElement; + } + this.render = function () { KB.on('modal.stop', onStop); KB.on('modal.disable', onDisable); @@ -86,9 +92,11 @@ KB.component('submit-buttons', function (containerElement, options) { KB.removeListener('modal.submit.label', onUpdateSubmitLabel); }); + submitButtonElement = buildButton(); + var formActionElementBuilder = KB.dom('div') .attr('class', 'form-actions') - .add(buildButton()); + .add(submitButtonElement); if (KB.modal.isOpen()) { formActionElementBuilder -- cgit v1.2.3