diff --git a/addons/survey/static/src/question_page/question_page_one2many_field.js b/addons/survey/static/src/question_page/question_page_one2many_field.js index 16faf8f77ae..67671a1313b 100644 --- a/addons/survey/static/src/question_page/question_page_one2many_field.js +++ b/addons/survey/static/src/question_page/question_page_one2many_field.js @@ -2,12 +2,31 @@ import { QuestionPageListRenderer } from "./question_page_list_renderer"; import { registry } from "@web/core/registry"; -import { useOpenX2ManyRecord, useX2ManyCrud } from "@web/views/fields/relational_utils"; +import { useOpenX2ManyRecord, useX2ManyCrud, X2ManyFieldDialog } from "@web/views/fields/relational_utils"; +import { patch } from '@web/core/utils/patch'; import { useService } from "@web/core/utils/hooks"; import { X2ManyField } from "@web/views/fields/x2many/x2many_field"; const { useSubEnv } = owl; +patch(X2ManyFieldDialog.prototype, 'survey_question_chaining_with_validation', { + /** + * Re-enable buttons after our error is thrown because blocking normal + * behavior is required to not close the dialog and stay in edition but + * the buttons are required to try and save again after changing form data. + * + * @override + */ + async saveAndNew() { + const res = this._super(...arguments); + if (this.record.resModel === 'survey.question') { + const btns = this.modalRef.el.querySelectorAll(".modal-footer button"); // see XManyFieldDialog.disableButtons + this.enableButtons(btns); + } + return res; + } +}); + class QuestionPageOneToManyField extends X2ManyField { setup() { super.setup(); @@ -95,7 +114,7 @@ class QuestionPageOneToManyField extends X2ManyField { } ); // Prevent closing the question form view - return Promise.reject("Impossible to save survey, see error notification."); + throw error; } } QuestionPageOneToManyField.components = {