Skip to content

Commit

Permalink
cms_form: wizrd optional confirm submit modal
Browse files Browse the repository at this point in the history
You can now enable and optional confirm modal before submitting a wizard.
  • Loading branch information
simahawk committed Nov 3, 2023
1 parent 148e875 commit 9e4135a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cms_form/models/cms_form_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class CMSFormMixin(models.AbstractModel):
form_content_selector = fields.Char(form_tech=True, default=".form_content")
# used to interpolate widgets' html field name
form_fname_pattern = fields.Char(form_tech=True, default="")
# used enable submit confirmation at last step
form_confirm_submit = fields.Boolean(form_tech=True, default="")

def _valid_field_parameter(self, field, name):
res = super()._valid_field_parameter(field, name)
Expand Down Expand Up @@ -738,3 +740,7 @@ def _form_info_merge(self, info, tomerge):
you can use this method to merge them properly.
"""
return utils.data_merge(info, tomerge)

@property
def form_msg_confirm_submit(self):
return _("Are you sure want to submit the form as it is?")

Check warning on line 746 in cms_form/models/cms_form_mixin.py

View check run for this annotation

Codecov / codecov/patch

cms_form/models/cms_form_mixin.py#L746

Added line #L746 was not covered by tests
51 changes: 50 additions & 1 deletion cms_form/templates/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,12 @@ License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
</t>
<t t-else="">
<button
type="submit"
t-att-type="'button' if form.form_confirm_submit else 'submit'"
name="wiz_submit"
value="process"
class="btn btn-primary float-end"
t-att-data-bs-toggle="'modal' if form.form_confirm_submit else None"
t-att-data-bs-target="'#process-confirm-modal' if form.form_confirm_submit else None"
>Submit</button>
</t>
<t t-if="form.wiz_prev_step()">
Expand All @@ -387,6 +389,53 @@ License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
>Prev</button>
</t>
</div>
<t
t-if="form.form_confirm_submit"
t-call="cms_form.wizard_form_confirm_modal"
/>
</xpath>
</template>


<template id="wizard_form_confirm_modal" name="CMS wizard form confirm modal">
<!-- Modal -->
<div
class="modal fade"
id="process-confirm-modal"
tabindex="-1"
aria-labelledby="process-confirm-modal"
aria-hidden="true"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Confirm submit</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
/>
</div>
<div class="modal-body">
<p t-esc="form.form_msg_confirm_submit" />
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-default"
data-bs-dismiss="modal"
>Close</button>
<button
type="submit"
name="wiz_submit"
value="process"
class="btn btn-primary"
>Submit</button>
</div>
</div>
</div>
</div>
</template>

</odoo>

0 comments on commit 9e4135a

Please sign in to comment.