From d4801222997f04933e5bc316656eeaab553ced14 Mon Sep 17 00:00:00 2001
From: alexisben <alex@noesya.coop>
Date: Fri, 27 Jan 2023 15:58:50 +0100
Subject: [PATCH] add tiny js helper to validate form on click on html node
 parent

---
 .../admin/utils/validate_click_form.js        | 46 +++++++++++++++++++
 .../admin/communication/blocks/new.html.erb   |  2 +-
 2 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 app/assets/javascripts/admin/utils/validate_click_form.js

diff --git a/app/assets/javascripts/admin/utils/validate_click_form.js b/app/assets/javascripts/admin/utils/validate_click_form.js
new file mode 100644
index 000000000..c3e0bab8b
--- /dev/null
+++ b/app/assets/javascripts/admin/utils/validate_click_form.js
@@ -0,0 +1,46 @@
+/* global $ */
+window.osuny.validateFromClickManager = {
+    init: function () {
+        'use strict';
+
+        this.elements = document.querySelectorAll('.js-validate-form-click');
+        
+        if (this.elements.length > 0) {
+            this.listen();
+        }
+    },
+
+    listen: function() {
+        'use strict';
+
+        this.elements.forEach(function(element) {
+            this.bindClick(element)
+        }.bind(this));
+    },
+
+    bindClick: function(element) {
+        'use strict';
+        var form = element.querySelector('form');
+
+        if (!form) {
+            return;
+        }
+
+        element.style.cursor = "pointer"
+        element.addEventListener('click', function() {
+            form.submit();
+        });
+    },
+
+    invoke: function () {
+        'use strict';
+        return {
+            init: this.init.bind(this)
+        };
+    }
+}.invoke();
+
+window.addEventListener('DOMContentLoaded', function () {
+    'use strict';
+    window.osuny.validateFromClickManager.init();
+});
diff --git a/app/views/admin/communication/blocks/new.html.erb b/app/views/admin/communication/blocks/new.html.erb
index 7fdb0aa1d..0676c2d09 100644
--- a/app/views/admin/communication/blocks/new.html.erb
+++ b/app/views/admin/communication/blocks/new.html.erb
@@ -14,7 +14,7 @@
         %>
         <% next unless template.allowed_for_about? %>
         <div class="col-xxl-2 col-lg-3 col-md-4 d-flex">
-          <div class="<%= 'card' if current_admin_theme == 'appstack' %> flex-fill position-relative">
+          <div class="<%= 'card' if current_admin_theme == 'appstack' %> flex-fill position-relative js-validate-form-click">
             <%= image_tag "communication/blocks/templates/#{kind}.jpg", alt: '', class:"card-img-top block__image" %>
             <div class="<%= 'card-body' if current_admin_theme == 'appstack' %>">
                 <h3 class="h4 block__title"><%= t "enums.communication.block.template_kind.#{kind}" %></h4>
-- 
GitLab