Use a date field to select the date of birth

The default `date_select` used in fields presents an accessibility
issue, because in generates three select controls but only one label.
That means that there are two controls without a label.

So we're using a date field instead. This type is field is supported by
about 99% of the browsers, and we've already got JavaScript code
converting this field to a jQuery UI datepicker in case the browser
doesn't support date fields.

Note that, since we no longer need to parse the three date fields into
one, we can simplify the code in both the models and the tests.

Another slight improvement is that, previously, we couldn't restrict the
month and day controls in order to set the minimum date, so the maximum
selectable date was always the 31st of December of the year set by the
minimum age setting. As seen in the component test, now that we use only
one field, we can set a specific date as the maximum one.
This commit is contained in:
Javi Martín
2024-10-12 16:50:40 +02:00
parent 6af8ddd324
commit 3b7948a139
16 changed files with 35 additions and 90 deletions

View File

@@ -1,8 +1,9 @@
class Verification::Management::Document
include ActiveModel::Model
include ActiveModel::Dates
include ActiveModel::Attributes
attr_accessor :document_type, :document_number, :date_of_birth, :postal_code
attribute :date_of_birth, :date
attr_accessor :document_type, :document_number, :postal_code
validates :document_type, :document_number, presence: true
validates :date_of_birth, presence: true, if: -> { Setting.force_presence_date_of_birth? }
@@ -10,12 +11,6 @@ class Verification::Management::Document
delegate :username, :email, to: :user, allow_nil: true
def initialize(attrs = {})
self.date_of_birth = parse_date("date_of_birth", attrs)
attrs = remove_date("date_of_birth", attrs)
super
end
def user
@user = User.active.by_document(document_type, document_number).first
end

View File

@@ -1,9 +1,10 @@
class Verification::Residence
include ActiveModel::Model
include ActiveModel::Dates
include ActiveModel::Attributes
include ActiveModel::Validations::Callbacks
attr_accessor :user, :document_number, :document_type, :date_of_birth, :postal_code, :terms_of_service
attribute :date_of_birth, :date
attr_accessor :user, :document_number, :document_type, :postal_code, :terms_of_service
validates :document_number, presence: true
validates :document_type, presence: true
@@ -18,8 +19,6 @@ class Verification::Residence
validate :local_residence
def initialize(attrs = {})
self.date_of_birth = parse_date("date_of_birth", attrs)
attrs = remove_date("date_of_birth", attrs)
super
clean_document_number
end