Skip to content

Commit

Permalink
Converts title input to a dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDancingClown committed May 16, 2024
1 parent e671eef commit af5535c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class User < ApplicationRecord
extend Enumerize

POSSIBLE_ROLES = %w(account_admin regular)
POSSIBLE_TITLES = %w(Mr Sir Miss Ms Mx Mrs Dr Professor Reverend)

devise :database_authenticatable, :registerable,
:recoverable, :trackable, :validatable, :confirmable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
.row
.col-md-2
= f.input :head_of_business_title,
as: :string,
as: :select,
label: "Title",
input_html: { class: "form-control" }
input_html: { class: "form-control" },
collection: User::POSSIBLE_TITLES,
include_blank: false
.col-md-3
= f.input :head_of_business_first_name,
as: :string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
.row
.col-md-2
= f.input :title,
as: :string,
as: :select,
label: "Title",
input_html: { class: 'form-control' }
input_html: { class: 'form-control' },
collection: User::POSSIBLE_TITLES,
include_blank: false
.row
.col-md-8
= f.input :name,
Expand Down Expand Up @@ -55,4 +57,4 @@
.form-actions.text-right
= link_to "Cancel", "#", class: "btn btn-default form-cancel-link if-no-js-hide", data: { element_focus_target: "dismiss" }
= f.submit "Save", class: "btn btn-primary form-save-link pull-right"
.clear
.clear
34 changes: 24 additions & 10 deletions app/views/qae_form/_sub_fields_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,27 @@ div role="group" id="#{question.key}"

- klass <<(QaeFormBuilder::SubFieldsQuestionDecorator::NO_VALIDATION_SUB_FIELDS.exclude?(sub_field_key) ? " required" : " not-required")

input.govuk-input.js-trigger-autosave[
class=klass
type="text"
id=question.input_name(suffix: sub_field_key)
value=question.input_value(suffix: sub_field_key)
name=question.input_name(suffix: sub_field_key)
autocomplete="off" *possible_read_only_ops
data-word-max=question.sub_fields_words_max
aria-describedby=(@form_answer.validator_errors && @form_answer.validator_errors[question.hash_key] ? "error_for_#{sub_field_key}" : nil )
]
- if sub_field_key == :title
select.govuk-select.js-trigger-autosave[
class=klass
name=question.input_name(suffix: sub_field_key)
id=question.input_name(suffix: sub_field_key)
aria-describedby=(@form_answer.validator_errors && @form_answer.validator_errors[question.hash_key] ? "error_for_#{sub_field_key}" : nil )
]
option value='' disabled=true selected=(!User::POSSIBLE_TITLES.include?(question.input_value(suffix: sub_field_key)))
| Select a title
- User::POSSIBLE_TITLES.each do |option|
option value="#{option}" selected=((question.input_value(suffix: sub_field_key)).to_s == option.to_s)
= option

- else
input.govuk-input.js-trigger-autosave[
class=klass
type="text"
id=question.input_name(suffix: sub_field_key)
value=question.input_value(suffix: sub_field_key)
name=question.input_name(suffix: sub_field_key)
autocomplete="off" *possible_read_only_ops
data-word-max=question.sub_fields_words_max
aria-describedby=(@form_answer.validator_errors && @form_answer.validator_errors[question.hash_key] ? "error_for_#{sub_field_key}" : nil )
]

0 comments on commit af5535c

Please sign in to comment.