diff --git a/app/javascript/controllers/collections_form_controller.js b/app/javascript/controllers/collections_form_controller.js new file mode 100644 index 000000000..2ee872b4c --- /dev/null +++ b/app/javascript/controllers/collections_form_controller.js @@ -0,0 +1,21 @@ +import { Controller } from "@hotwired/stimulus" +import { nextEventLoopTick } from "helpers/timing_helpers"; + +export default class extends Controller { + static targets = ["meCheckbox"] + static values = { selfRemovalPromptMessage: { type: String, default: "Are you sure?" } } + + async submitWithWarning(event) { + if (this.hasMeCheckboxTarget && !this.meCheckboxTarget.checked && !this.confirmed) { + event.detail.formSubmission.stop() + + const message = this.selfRemovalPromptMessageValue + + if (confirm(message)) { + await nextEventLoopTick() + this.confirmed = true + this.element.requestSubmit() + } + } + } +} diff --git a/app/views/collections/_access_toggle.erb b/app/views/collections/_access_toggle.erb index 776e2f017..9940d6b14 100644 --- a/app/views/collections/_access_toggle.erb +++ b/app/views/collections/_access_toggle.erb @@ -9,7 +9,9 @@ <%= icon_tag "check", class: "toggler__visible-when-on margin-inline-end" %> diff --git a/app/views/collections/edit.html.erb b/app/views/collections/edit.html.erb index 1b95d3f27..6d3b50f50 100644 --- a/app/views/collections/edit.html.erb +++ b/app/views/collections/edit.html.erb @@ -21,7 +21,7 @@