From c8e03fa5e3eeab18c78dfad68fdfce2dad002301 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 28 Aug 2024 21:37:38 +0200 Subject: [PATCH] Allow to set input_type on Datetime ingredient editor Since the Datetime ingredient stores date and time values it should be possible to set the input_type to either - time - date - datetime (cherry picked from commit 02a69a65a532e9d7233ee7cc23c96afc5a049bd7) # Conflicts: # app/views/alchemy/ingredients/_datetime_editor.html.erb # spec/views/alchemy/ingredients/datetime_editor_spec.rb --- app/models/alchemy/ingredients/datetime.rb | 2 +- app/views/alchemy/ingredients/_datetime_editor.html.erb | 3 ++- spec/dummy/config/alchemy/elements.yml | 2 ++ spec/models/alchemy/ingredients/datetime_spec.rb | 6 ++++++ spec/views/alchemy/ingredients/datetime_editor_spec.rb | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/alchemy/ingredients/datetime.rb b/app/models/alchemy/ingredients/datetime.rb index 5bb7794d23..a3953829fa 100644 --- a/app/models/alchemy/ingredients/datetime.rb +++ b/app/models/alchemy/ingredients/datetime.rb @@ -5,7 +5,7 @@ module Ingredients # A datetime value # class Datetime < Alchemy::Ingredient - allow_settings %i[date_format] + allow_settings %i[date_format input_type] def value ActiveRecord::Type::DateTime.new.cast(self[:value]) diff --git a/app/views/alchemy/ingredients/_datetime_editor.html.erb b/app/views/alchemy/ingredients/_datetime_editor.html.erb index 1d4524250b..a318475f04 100644 --- a/app/views/alchemy/ingredients/_datetime_editor.html.erb +++ b/app/views/alchemy/ingredients/_datetime_editor.html.erb @@ -7,7 +7,8 @@ datetime_editor, :value, { name: datetime_editor.form_field_name, id: datetime_editor.form_field_id, - value: datetime_editor.value + value: datetime_editor.value, + type: datetime_editor.settings[:input_type] } ) %> <% end %> diff --git a/spec/dummy/config/alchemy/elements.yml b/spec/dummy/config/alchemy/elements.yml index e17fc01680..a8936248ac 100644 --- a/spec/dummy/config/alchemy/elements.yml +++ b/spec/dummy/config/alchemy/elements.yml @@ -123,6 +123,8 @@ - role: datetime type: Datetime hint: true + settings: + input_type: datetime - role: file type: File hint: true diff --git a/spec/models/alchemy/ingredients/datetime_spec.rb b/spec/models/alchemy/ingredients/datetime_spec.rb index 4df72dd9c5..aba0893d49 100644 --- a/spec/models/alchemy/ingredients/datetime_spec.rb +++ b/spec/models/alchemy/ingredients/datetime_spec.rb @@ -16,6 +16,12 @@ ) end + describe ".allowed_settings" do + it "sets allowed_settings" do + expect(described_class.allowed_settings).to eq([:date_format, :input_type]) + end + end + describe "value" do subject { datetime_ingredient.value } diff --git a/spec/views/alchemy/ingredients/datetime_editor_spec.rb b/spec/views/alchemy/ingredients/datetime_editor_spec.rb index 5bec45db8f..fe0ffe7abd 100644 --- a/spec/views/alchemy/ingredients/datetime_editor_spec.rb +++ b/spec/views/alchemy/ingredients/datetime_editor_spec.rb @@ -17,6 +17,6 @@ it "renders a datepicker" do render element_editor - expect(rendered).to have_css('input[type="text"][data-datepicker-type="date"].date') + expect(rendered).to have_css('input[type="text"][data-datepicker-type="datetime"].datetime') end end