Skip to content
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
4 changes: 2 additions & 2 deletions app/views/affiliations/_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
label_html: { class: "block text-sm font-medium text-gray-700 mb-1" },
input_html: {
type: "date",
value: (f.object.start_date || (Date.current unless f.object.persisted?))&.strftime("%Y-%m-%d"),
value: (f.object.start_date || (Date.current.beginning_of_month unless f.object.persisted?))&.strftime("%Y-%m-%d"),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€– From Claude: Both defaults only apply to unpersisted rows (unless f.object.persisted? for the date; primary_contact? reflects the stored value for existing rows), so editing an existing affiliation is unaffected.

class: "rounded-md border-gray-300 focus:ring-blue-500 focus:border-blue-500 text-sm",
data: { action: "change->affiliation-dates#recalculate" }
} %>
Expand All @@ -94,7 +94,7 @@
<div class="w-full sm:w-auto pb-3">
<label class="block whitespace-nowrap text-sm font-medium text-gray-700 mb-1">Primary org<br>contact</label>
<%= f.check_box :primary_contact,
checked: f.object.primary_contact? || !f.object.persisted?,
checked: f.object.primary_contact?,
class: "h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" %>
</div>

Expand Down
11 changes: 11 additions & 0 deletions spec/views/organizations/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,15 @@ def org_with_status(name)
assert_select "p.text-red-600", text: "Does not match affiliations status"
end
end

describe "new affiliation defaults" do
it "defaults the start date to the first of the current month and leaves primary contact unchecked" do
organization.affiliations.build
render
assert_select "input[name*='start_date'][value=?]",
Date.current.beginning_of_month.strftime("%Y-%m-%d")
assert_select "input[type=checkbox][name*='primary_contact']"
assert_select "input[type=checkbox][name*='primary_contact'][checked]", false
end
end
end