From 3360e054aa74908448837a452e32d6fa7606ad91 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 18 Oct 2023 12:56:03 +0200 Subject: [PATCH] Add a generic controller for blocking access to fields while a form is submitted --- .../readonly_when_submitting_controller.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 admin/app/javascript/solidus_admin/controllers/readonly_when_submitting_controller.js diff --git a/admin/app/javascript/solidus_admin/controllers/readonly_when_submitting_controller.js b/admin/app/javascript/solidus_admin/controllers/readonly_when_submitting_controller.js new file mode 100644 index 00000000000..14b779bbda4 --- /dev/null +++ b/admin/app/javascript/solidus_admin/controllers/readonly_when_submitting_controller.js @@ -0,0 +1,17 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + this.element.addEventListener("submit", this) + } + + disconnect() { + this.element.removeEventListener("submit", this) + } + + handleEvent() { + for (const element of this.element.elements) { + element.setAttribute("readonly", true) + } + } +}