Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.0-stable] Allow to set input_type on Datetime ingredient editor #3014

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading