Skip to content

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

Allow specifiying a name for date picker names

Klaus Zanderse896ddabd572
diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rb
index 8bcad6d282c..83fe198dd42 100644
--- a/lib/tabular_form_builder.rb
+++ b/lib/tabular_form_builder.rb
@@ -100,7 +100,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
inputs = {
value: @object.public_send(field),
id: field_id(field, index: options[:index]),
- name: field_name(field, index: options[:index])
+ name: options[:name] || field_name(field, index: options[:index])
}
if options.dig(:data, :"remote-field-key")
diff --git a/spec/lib/tabular_form_builder_spec.rb b/spec/lib/tabular_form_builder_spec.rb
index 4fc11ea5259..53f299bb3f1 100644
--- a/spec/lib/tabular_form_builder_spec.rb
+++ b/spec/lib/tabular_form_builder_spec.rb
@@ -268,6 +268,24 @@ JJ Abrams</textarea>
end
end
+ describe "#date_picker" do
+ let(:options) { { title: "Last logged in", name: "user[custom_field_values][12]" } }
+
+ subject(:output) do
+ builder.date_picker :last_login_on, options
+ end
+
+ it_behaves_like "labelled by default"
+ it_behaves_like "wrapped in field-container by default"
+
+ it "outputs element" do
+ puts output
+ expect(output).to have_css "op-basic-single-date-picker"
+ # Regression test, allow for the name to be passed through
+ expect(output).to have_css "op-basic-single-date-picker[data-name='\"#{options[:name]}\"']"
+ end
+ end
+
describe "#date_select" do
let(:options) { { title: "Last logged in on" } }