Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort confirmation modal flow if attached form is invalid #2253

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions evap/evaluation/templates/confirmation_text_modal.html

This file was deleted.

5 changes: 1 addition & 4 deletions evap/staff/templates/staff_semester_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ <h3 class="m-0 me-1">{{ semester.name }}</h3>

<confirmation-modal type="submit" confirm-button-class="btn-danger">
<span slot="title">{% translate 'Delete semester' %}</span>
<span slot="action-text">{% translate 'Delete semester' %}</span>
<span slot="question">
{% blocktranslate trimmed with semester_name=semester.name %}
Do you really want to delete the semester <strong>{{ semester_name }}</strong>?
Expand All @@ -52,10 +53,6 @@ <h3 class="m-0 me-1">{{ semester.name }}</h3>
<input type="text" name="validated-semester-name" data-must-equal="{{ semester.name }}" class="form-control" />
</div>

<span slot="submit-group">
<button class="btn btn-danger ms-2">{% translate 'Delete semester' %}</button>
</span>

<button
slot="show-button"
type="button"
Expand Down
8 changes: 7 additions & 1 deletion evap/static/ts/src/confirmation-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ export class ConfirmationModal extends HTMLElement {
onDialogFormSubmit = (event: SubmitEvent) => {
event.preventDefault();

const isConfirm = event.submitter?.dataset?.eventType === "confirm";

if (isConfirm && this.internals.form && !this.internals.form.reportValidity()) {
return;
}

this.closeDialogSlowly();

if (event.submitter?.dataset?.eventType === "confirm") {
if (isConfirm) {
if (this.type === "submit") {
// Unfortunately, `this` cannot act as the submitter of the form. Instead, we make our `value` attribute
// visible to the form until submission is finished (the `submit` handlers of the form might cancel the
Expand Down