-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak key people validation handling and heading (#95)
These changes are following the QA review. The bulk of the changes are about how we handle validation messages. This commit reduces the number of validation errors which a user can get at one time: - Previously a totally blank form would trigger about 6 different messages - now it should just be one - Date validation errors have also been simplified so if all fields are missing, we only display a single message - We also only check that the complete date is a valid date once we've validated the individual fields to reduce the number of errors users get - Date fields which don't contain valid integers are no longer converted to 0, which gives us better messages too Also changed the heading text for overseas users to match the wireframe.
- Loading branch information
1 parent
1d34814
commit 2e6964e
Showing
6 changed files
with
98 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class KeyPeopleValidator < ActiveModel::Validator | ||
def validate(record) | ||
return false unless fields_have_content?(record) | ||
validate_first_name(record) | ||
validate_last_name(record) | ||
DateOfBirthValidator.new.validate(record) | ||
end | ||
|
||
private | ||
|
||
def fields_have_content?(record) | ||
fields = [record.first_name, record.last_name, record.dob_day, record.dob_month, record.dob_year] | ||
fields.each do |field| | ||
return true if field.present? && field.to_s.length.positive? | ||
end | ||
record.errors.add(:base, :not_enough_key_people) | ||
false | ||
end | ||
|
||
def validate_first_name(record) | ||
return unless field_is_present?(record, :first_name) | ||
field_is_not_too_long?(record, :first_name, 35) | ||
end | ||
|
||
def validate_last_name(record) | ||
return unless field_is_present?(record, :last_name) | ||
field_is_not_too_long?(record, :last_name, 35) | ||
end | ||
|
||
def field_is_present?(record, field) | ||
return true if record.send(field).present? | ||
record.errors.add(field, :blank) | ||
false | ||
end | ||
|
||
def field_is_not_too_long?(record, field, length) | ||
return true if record.send(field).length < length | ||
record.errors.add(field, :too_long) | ||
false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters