Skip to content

Commit

Permalink
Pass raw autocomplete attribute
Browse files Browse the repository at this point in the history
This allows us to handle the situation where the user has cleared the
field (but the autocomplete value is retained). We can check the raw
value of the field, if it's empty we know we should ignore the
autocomplete value.
  • Loading branch information
thomasleese committed Sep 7, 2023
1 parent c0833fd commit 34779f0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,11 @@ def confirm_age_range_subjects_form_params
:age_range_max,
:age_range_note,
:subject_1,
:subject_1_raw,
:subject_2,
:subject_2_raw,
:subject_3,
:subject_3_raw,
:subjects_note,
)
end
Expand Down
3 changes: 3 additions & 0 deletions app/forms/assessor_interface/check_age_range_subjects_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ def permittable_parameters
age_range_max
age_range_note
subject_1
subject_1_raw
subject_2
subject_2_raw
subject_3
subject_3_raw
subjects_note
]
[args, kwargs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ module AssessorInterface::AgeRangeSubjectsForm
}

attribute :subject_1, :string
attribute :subject_1_raw, :string
attribute :subject_2, :string
attribute :subject_2_raw, :string
attribute :subject_3, :string
attribute :subject_3_raw, :string
attribute :subjects_note, :string

validates :subject_1, presence: true
validates :subject_1_raw, presence: true
end

def save
Expand All @@ -52,7 +56,11 @@ def update_age_range
end

def update_subjects
subjects = [subject_1, subject_2, subject_3].compact_blank
subjects = [
subject_1_raw.present? ? subject_1 : "",
subject_2_raw.present? ? subject_2 : "",
subject_3_raw.present? ? subject_3 : "",
].compact_blank
note = subjects_note.presence || ""
assessment.update!(subjects:, subjects_note: note)
end
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ var loadCountryAutoComplete = () => {
};

loadCountryAutoComplete();
dfeAutocomplete({});
dfeAutocomplete({ rawAttribute: true });

checkboxSearchFilter("app-applications-filters-assessor", "Search assessors");
9 changes: 8 additions & 1 deletion spec/support/shared_examples/age_range_subjects_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
it { is_expected.to_not validate_presence_of(:age_range_note) }

it { is_expected.to validate_presence_of(:subject_1) }
it { is_expected.to validate_presence_of(:subject_1_raw) }
it { is_expected.to_not validate_presence_of(:subject_2) }
it { is_expected.to_not validate_presence_of(:subject_3) }
it { is_expected.to_not validate_presence_of(:subjects_note) }
Expand All @@ -48,7 +49,12 @@

describe "with valid attributes and no note" do
let(:age_range_subjects_attributes) do
{ age_range_min: "7", age_range_max: "11", subject_1: "Subject" }
{
age_range_min: "7",
age_range_max: "11",
subject_1: "Subject",
subject_1_raw: "Subject",
}
end

it { is_expected.to be true }
Expand Down Expand Up @@ -79,6 +85,7 @@
age_range_max: "11",
age_range_note: "A note.",
subject_1: "Subject",
subject_1_raw: "Subject",
subjects_note: "Another note.",
}
end
Expand Down

0 comments on commit 34779f0

Please sign in to comment.