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

Fix datepicker in resource forms #2760

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
Fix datepicker in resource forms
The attribute that the `<alchemy-datepicker>` custom element
needs to init the appropriate Datepickr type is called `input-type`
and not a `data-` attribute anymore.
tvdeyen committed Feb 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5791a1310d66cff37ec28ab692e2589a0cf42323
2 changes: 1 addition & 1 deletion lib/alchemy/forms/builder.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 1 addition & 6 deletions lib/alchemy/resources_helper.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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
2 changes: 1 addition & 1 deletion spec/libraries/forms/builder_spec.rb
Original file line number Diff line number Diff line change
@@ -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

15 changes: 3 additions & 12 deletions spec/libraries/resources_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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