Skip to content

Commit

Permalink
Merge pull request #3002 from AlchemyCMS/fix-datetime-editor-input_type
Browse files Browse the repository at this point in the history
Allow to set input_type on Datetime ingredient editor
  • Loading branch information
tvdeyen authored Aug 29, 2024
2 parents 8d88024 + 02a69a6 commit 3513fd1
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 @@ -8,7 +8,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]
}
) %>
<label for="<%= datetime_editor.form_field_id %>" class="ingredient-date--label">
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 @@ -128,6 +128,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('alchemy-datepicker[input-type="date"] input[type="text"].date')
expect(rendered).to have_css('alchemy-datepicker[input-type="datetime"] input[type="text"].datetime')
end
end

0 comments on commit 3513fd1

Please sign in to comment.