OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix submit with hidden sections
Oliver Günther58e8eb1044ee
diff --git a/app/views/custom_actions/_form.html.erb b/app/views/custom_actions/_form.html.erbindex ee0a0fd0ddc..fb2e176277e 100644--- a/app/views/custom_actions/_form.html.erb+++ b/app/views/custom_actions/_form.html.erb@@ -1,4 +1,3 @@-<% content_controller "hide-sections", dynamic: true %><% active_section_keys = @custom_action.actions.map(&:key) %><div class="form--field -required">diff --git a/app/views/custom_actions/edit.html.erb b/app/views/custom_actions/edit.html.erbindex a65ea495f3f..c225bef9046 100644--- a/app/views/custom_actions/edit.html.erb+++ b/app/views/custom_actions/edit.html.erb@@ -43,7 +43,10 @@ See COPYRIGHT and LICENSE files for more details.<%= error_messages_for @custom_action %>-<%= labelled_tabular_form_for @custom_action do |f| %>+<% content_controller "hide-sections", dynamic: true %>++<%= labelled_tabular_form_for @custom_action,+ data: { "hide-sections-target": "form" } do |f| %><%= render partial: "form", locals: { f: f } %><%= styled_button_tag t(:button_save), class: "-primary -with-icon icon-checkmark" %><% end %>diff --git a/app/views/custom_actions/new.html.erb b/app/views/custom_actions/new.html.erbindex a0974bce9e9..2a21b41053f 100644--- a/app/views/custom_actions/new.html.erb+++ b/app/views/custom_actions/new.html.erb@@ -43,7 +43,10 @@ See COPYRIGHT and LICENSE files for more details.<%= error_messages_for @custom_action %>-<%= labelled_tabular_form_for @custom_action do |f| %>+<% content_controller "hide-sections", dynamic: true %>++<%= labelled_tabular_form_for @custom_action,+ data: { "hide-sections-target": "form" } do |f| %><%= render partial: "form", locals: { f: f } %><%= styled_button_tag t(:button_create), class: "-primary -with-icon icon-checkmark" %><% end %>diff --git a/frontend/src/stimulus/controllers/dynamic/hide-sections.controller.ts b/frontend/src/stimulus/controllers/dynamic/hide-sections.controller.tsindex bb4590c4663..4a856137199 100644--- a/frontend/src/stimulus/controllers/dynamic/hide-sections.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/hide-sections.controller.ts@@ -1,12 +1,25 @@import { Controller } from '@hotwired/stimulus';+import { navigator } from '@hotwired/turbo';export default class extends Controller {- static targets = ['section', 'select'];+ static targets = ['section', 'select', 'form'];declare readonly sectionTargets:HTMLElement[];declare readonly selectTarget:HTMLSelectElement;+ declare readonly formTarget:HTMLFormElement;++ private boundSubmitListener = this.onSubmit.bind(this);++ formTargetConnected(target:HTMLFormElement) {+ target.addEventListener('submit', this.boundSubmitListener);+ }++ formTargetDisconnected(target:HTMLFormElement) {+ target.removeEventListener('submit', this.boundSubmitListener);+ }+add(event:Event) {const selectedValue = (event.target as HTMLSelectElement).value;if (!selectedValue) {@@ -42,4 +55,22 @@ export default class extends Controller {option.disabled = !option.disabled;}++ // Remove hidden sections on submit+ onSubmit(event:SubmitEvent) {+ if (this.formTarget.dataset.confirmed === 'true' || this.sectionTargets.length === 0) {+ return true;+ }++ this.formTarget.dataset.confirmed = 'true';+ this.sectionTargets.forEach((section) => {+ if (section.hidden) {+ section.remove();+ }+ });++ event.preventDefault();+ navigator.submitForm(this.formTarget, event?.submitter || undefined);+ return false;+ }}