Skip to content

Commit

Permalink
Merge pull request #3014 from AlchemyCMS/backport/7.0-stable/pr-3002
Browse files Browse the repository at this point in the history
[7.0-stable] Allow to set input_type on Datetime ingredient editor
  • Loading branch information
tvdeyen authored Sep 4, 2024
2 parents 6e74d2b + c8e03fa commit 4a92bea
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/alchemy/ingredients/datetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
3 changes: 2 additions & 1 deletion app/views/alchemy/ingredients/_datetime_editor.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/config/alchemy/elements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
- role: datetime
type: Datetime
hint: true
settings:
input_type: datetime
- role: file
type: File
hint: true
Expand Down
6 changes: 6 additions & 0 deletions spec/models/alchemy/ingredients/datetime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion spec/views/alchemy/ingredients/datetime_editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4a92bea

Please sign in to comment.