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.1-stable] Fix datepicker in resource forms #2762

Merged
merged 1 commit into from
Feb 29, 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 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
Loading