[FIX] website_slides: create new sections only once

Bug to reproduce
----------------

- Log in as admin
- Go to the frontend page of a course
- Click on 'Add Section'
- Fill the form (name input)
- Press 'Enter' or click on save button x times
x sections with the same name will be created

Specifications
--------------

Prevent the 'Add section' form being submitted multiple times in a row.

task-3432418

closes odoo/odoo#131107

X-original-commit: a91a60b4be5b2f606d20fbe574625b85e43407f6
Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
Lopes Marc (loma)
2023-08-08 08:56:12 +02:00
parent 8989a211bc
commit 248ee476fd
@@ -6,6 +6,10 @@ import { _t } from "@web/legacy/js/services/core";
var CategoryAddDialog = Dialog.extend({
template: 'slides.category.add',
events: Object.assign(
{ "submit form#slide_category_add_form": "_onClickFormSubmit" },
Dialog.events
),
/**
* @override
@@ -16,8 +20,8 @@ var CategoryAddDialog = Dialog.extend({
size: 'medium',
buttons: [{
text: _t('Save'),
classes: 'btn-primary',
click: this._onClickFormSubmit.bind(this)
classes: 'btn-primary o_js_website_slides_add_category_btn',
click: this._onClickFormSubmit.bind(this),
}, {
text: _t('Back'),
close: true
@@ -37,10 +41,24 @@ var CategoryAddDialog = Dialog.extend({
return $form[0].checkValidity();
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* Handle form submission on click button or press ENTER key. Prevent multiple submissions
* @private
* @param {Event} ev
*/
_onClickFormSubmit: function (ev) {
var $form = this.$('#slide_category_add_form');
if (this._formValidate($form)) {
$form.submit();
ev.preventDefault();
const form = document.getElementById("slide_category_add_form");
if (!form.classList.contains("o_js_website_slides_form_submitted")) {
if (this._formValidate($(form))) {
form.classList.add("o_js_website_slides_form_submitted");
document.querySelector("button.o_js_website_slides_add_category_btn").disabled = true;
form.submit();
}
}
},
});