Skip to content

Commit

Permalink
Merge pull request #2760 from tvdeyen/fix-resource-datepicker
Browse files Browse the repository at this point in the history
Fix datepicker in resource forms
  • Loading branch information
tvdeyen authored Feb 29, 2024
2 parents dd49458 + 5791a13 commit 38b5176
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/alchemy/forms/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def datepicker(attribute_name, options = {})
}.merge(options[:input_html] || {})

date_field = input attribute_name, as: :string, input_html: input_options
template.content_tag("alchemy-datepicker", date_field, type: type)
template.content_tag("alchemy-datepicker", date_field, "input-type" => type)
end

# Renders a simple_form input that displays a richtext editor
Expand Down
7 changes: 1 addition & 6 deletions lib/alchemy/resources_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ def resource_attribute_field_options(attribute)
when "boolean"
options
when "date", "time", "datetime"
options.merge(
as: "string",
input_html: {
data: {datepicker_type: input_type}
}
)
options.merge(as: input_type)
when "text"
options.merge(as: "text", input_html: {rows: 4})
else
Expand Down
10 changes: 5 additions & 5 deletions spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@
it "renders an input field according to the attribute's type" do
visit "/admin/events/new"
expect(page).to have_selector('input#event_name[type="text"]')
expect(page).to have_selector('input#event_starts_at[data-datepicker-type="datetime"]')
expect(page).to have_selector('input#event_ends_at[data-datepicker-type="datetime"]')
expect(page).to have_selector('alchemy-datepicker[input-type="datetime"] input#event_starts_at')
expect(page).to have_selector('alchemy-datepicker[input-type="datetime"] input#event_ends_at')
expect(page).to have_selector("textarea#event_description")
expect(page).to have_selector('input#event_published[type="checkbox"]')
expect(page).to have_selector('input#event_lunch_starts_at[data-datepicker-type="time"]')
expect(page).to have_selector('input#event_lunch_ends_at[data-datepicker-type="time"]')
expect(page).to have_selector('alchemy-datepicker[input-type="time"] input#event_lunch_starts_at')
expect(page).to have_selector('alchemy-datepicker[input-type="time"] input#event_lunch_ends_at')
end

it "should have a select box for associated models" do
Expand All @@ -202,7 +202,7 @@
describe "date fields" do
it "have date picker" do
visit "/admin/bookings/new"
expect(page).to have_selector('input#booking_from[data-datepicker-type="date"]')
expect(page).to have_selector('alchemy-datepicker[input-type="date"] input#booking_from')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/libraries/forms/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

shared_examples_for "datepicker expect" do
it "has the alchemy-datepicker" do
expect(template).to receive(:content_tag).with("alchemy-datepicker", "<alchemy-datepicker>", {type: type})
expect(template).to receive(:content_tag).with("alchemy-datepicker", "<alchemy-datepicker>", {"input-type" => type})
subject
end

Expand Down
15 changes: 3 additions & 12 deletions spec/libraries/resources_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ def resource_handler
is_expected.to match(
hash_including(
hint: nil,
as: "string",
input_html: {
data: {datepicker_type: "date"}
}
as: "date"
)
)
end
Expand All @@ -304,10 +301,7 @@ def resource_handler
is_expected.to match(
hash_including(
hint: nil,
as: "string",
input_html: {
data: {datepicker_type: "datetime"}
}
as: "datetime"
)
)
end
Expand All @@ -324,10 +318,7 @@ def resource_handler
is_expected.to match(
hash_including(
hint: nil,
as: "string",
input_html: {
data: {datepicker_type: "time"}
}
as: "time"
)
)
end
Expand Down

0 comments on commit 38b5176

Please sign in to comment.