Skip to content

Commit aacb1de

Browse files
committed
refactor(registration): enhance form structure and accessibility with improved IDs and grouping
1 parent 2f0411a commit aacb1de

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

app/views/devise/registrations/new.html.erb

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,115 +29,119 @@
2929
<% else %>
3030
<div class="row justify-content-center">
3131
<div class="col-md-6">
32-
<h2 class="mb-4"><%= t('.sign_up') %></h2>
32+
<h2 id="registration-title" class="mb-4"><%= t('.sign_up') %></h2>
3333

34-
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class: 'card card-body needs-validation', novalidate: true }, data: { controller: 'better_together--form-validation', turbo: false }) do |f| %>
34+
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { id: 'registration-form', class: 'card card-body needs-validation registration-form', novalidate: true }, data: { controller: 'better_together--form-validation', turbo: false }) do |f| %>
3535
<%= render "devise/shared/error_messages", resource: resource %>
3636

3737
<% if @platform_invitation %>
38-
<%= hidden_field_tag :invitation_code, @platform_invitation.token %>
38+
<%= hidden_field_tag :invitation_code, @platform_invitation.token, id: 'invitation-code-field' %>
3939
<% end %>
4040

4141
<!-- Email Field -->
42-
<div class="mb-3">
43-
<%= f.label :email, t('.email.label'), class: 'form-label' %>
44-
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control', required: true %>
45-
<small class="form-text text-muted"><%= t('.email.help') %></small>
42+
<div id="email-field-group" class="mb-3 form-field-group">
43+
<%= f.label :email, t('.email.label'), class: 'form-label', for: 'user_email' %>
44+
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control', required: true, id: 'user_email' %>
45+
<small id="email-help-text" class="form-text text-muted"><%= t('.email.help') %></small>
4646
</div>
4747

4848
<!-- Password Field -->
49-
<div class="mb-3" data-controller="better_together--password-toggle">
50-
<%= f.label :password, t('.password.label'), class: 'form-label' %>
49+
<div id="password-field-group" class="mb-3 form-field-group" data-controller="better_together--password-toggle">
50+
<%= f.label :password, t('.password.label'), class: 'form-label', for: 'user_password' %>
5151
<% if @minimum_password_length %>
52-
<em><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></em>
52+
<em id="password-length-requirement"><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></em>
5353
<% end %>
5454
<div class="input-group">
55-
<%= f.password_field :password, autocomplete: "current-password", class: 'form-control', "data-target": "better_together--password-toggle.field", required: true, minlength: @minimum_password_length || 12 %>
56-
<button type="button" data-action="click->better_together--password-toggle#password" class="btn btn-outline-secondary" data-bs-toggle="tooltip" title="<%= t('devise.sessions.new.password.toggle') %>">
55+
<%= f.password_field :password, autocomplete: "current-password", class: 'form-control', "data-target": "better_together--password-toggle.field", required: true, minlength: @minimum_password_length || 12, id: 'user_password' %>
56+
<button id="password-toggle-btn" type="button" data-action="click->better_together--password-toggle#password" class="btn btn-outline-secondary" data-bs-toggle="tooltip" title="<%= t('devise.sessions.new.password.toggle') %>">
5757
<i class="password-field-icon-1 far fa-eye-slash" data-target="better_together--password-toggle.icon"></i>
5858
</button>
5959
</div>
60-
<small class="form-text text-muted"><%= t('.password.help') %></small>
60+
<small id="password-help-text" class="form-text text-muted"><%= t('.password.help') %></small>
6161
</div>
6262

6363
<!-- Password Confirmation Field -->
64-
<div class="mb-3" data-controller="better_together--password-toggle">
65-
<%= f.label :password_confirmation, t('.password_confirmation.label'), class: 'form-label' %>
64+
<div id="password-confirmation-field-group" class="mb-3 form-field-group" data-controller="better_together--password-toggle">
65+
<%= f.label :password_confirmation, t('.password_confirmation.label'), class: 'form-label', for: 'user_password_confirmation' %>
6666

6767
<div class="input-group">
68-
<%= f.password_field :password_confirmation, autocomplete: "current-password", class: 'form-control', "data-target": "better_together--password-toggle.field", required: true, minlength: @minimum_password_length || 12 %>
69-
<button type="button" data-action="click->better_together--password-toggle#password" class="btn btn-outline-secondary" data-bs-toggle="tooltip" title="<%= t('devise.sessions.new.password.toggle') %>">
68+
<%= f.password_field :password_confirmation, autocomplete: "current-password", class: 'form-control', "data-target": "better_together--password-toggle.field", required: true, minlength: @minimum_password_length || 12, id: 'user_password_confirmation' %>
69+
<button id="password-confirmation-toggle-btn" type="button" data-action="click->better_together--password-toggle#password" class="btn btn-outline-secondary" data-bs-toggle="tooltip" title="<%= t('devise.sessions.new.password.toggle') %>">
7070
<i class="password-field-icon-1 far fa-eye-slash" data-target="better_together--password-toggle.icon"></i>
7171
</button>
7272
</div>
73-
<small class="form-text text-muted"><%= t('.password_confirmation.help') %></small>
73+
<small id="password-confirmation-help-text" class="form-text text-muted"><%= t('.password_confirmation.help') %></small>
7474
</div>
7575

76-
<div id="profile-details" class="mb-4">
77-
<h4><%= t('.profile_details') %></h4>
76+
<div id="profile-details" class="mb-4 profile-details-section">
77+
<h4 id="profile-details-title"><%= t('.profile_details') %></h4>
7878
<!-- Person Identification Fields -->
7979
<%= f.fields_for :person do |person_form| %>
8080
<!-- Name Field -->
81-
<div class="mb-3">
82-
<%= person_form.label :name, t('.person.name'), class: 'form-label' %>
83-
<%= person_form.text_field :name, class: "form-control", required: true %>
84-
<small class="form-text text-muted"><%= t('.person.name_hint') %></small>
81+
<div id="name-field-group" class="mb-3 form-field-group">
82+
<%= person_form.label :name, t('.person.name'), class: 'form-label', for: 'user_person_attributes_name' %>
83+
<%= person_form.text_field :name, class: "form-control", required: true, id: 'user_person_attributes_name' %>
84+
<small id="name-help-text" class="form-text text-muted"><%= t('.person.name_hint') %></small>
8585
</div>
8686

8787
<!-- Username Field -->
88-
<div class="mb-3">
89-
<%= person_form.label :identifier, t('.person.identifier'), class: 'form-label' %>
90-
<%= person_form.text_field :identifier, class: "form-control", required: true, minlength: 3 %>
88+
<div id="identifier-field-group" class="mb-3 form-field-group">
89+
<%= person_form.label :identifier, t('.person.identifier'), class: 'form-label', for: 'user_person_attributes_identifier' %>
90+
<%= person_form.text_field :identifier, class: "form-control", required: true, minlength: 3, id: 'user_person_attributes_identifier' %>
9191
<!-- Hint text for the Handle -->
92-
<small class="form-text text-muted"><%= t('.person.identifier_hint_html', platform: host_platform) %></small>
92+
<small id="identifier-help-text" class="form-text text-muted"><%= t('.person.identifier_hint_html', platform: host_platform) %></small>
9393
</div>
9494

9595
<!-- Description Field -->
96-
<div class="mb-3">
97-
<%= person_form.label :description, t('.person.description'), class: 'form-label' %>
98-
<%= person_form.text_area :description, class: "form-control" %>
99-
<small class="form-text text-muted"><%= t('.person.description_hint') %></small>
96+
<div id="description-field-group" class="mb-3 form-field-group">
97+
<%= person_form.label :description, t('.person.description'), class: 'form-label', for: 'user_person_attributes_description' %>
98+
<%= person_form.text_area :description, class: "form-control", id: 'user_person_attributes_description' %>
99+
<small id="description-help-text" class="form-text text-muted"><%= t('.person.description_hint') %></small>
100100
</div>
101101
<% end %>
102102
</div>
103103

104104
<% if @terms_of_service_agreement || @privacy_policy_agreement || @code_of_conduct_agreement %>
105+
<div id="agreements-section" class="agreements-section">
105106
<% if @terms_of_service_agreement %>
106-
<div class="mb-3 form-check">
107-
<%= check_box_tag :terms_of_service_agreement, '1', false, class: 'form-check-input agreement-checkbox', data: { agreement_identifier: 'terms_of_service' }, required: true, aria: { describedby: 'terms-of-service-summary', disabled: 'true' } %>
108-
<%= label_tag :terms_of_service_agreement, t('.terms_of_service.label'), class: 'form-check-label' %>
107+
<div id="terms-of-service-agreement-group" class="mb-3 form-check agreement-group">
108+
<%= check_box_tag :terms_of_service_agreement, '1', false, class: 'form-check-input agreement-checkbox', data: { agreement_identifier: 'terms_of_service' }, required: true, aria: { describedby: 'terms-of-service-summary', disabled: 'true' }, id: 'terms_of_service_agreement_checkbox' %>
109+
<%= label_tag :terms_of_service_agreement, t('.terms_of_service.label'), class: 'form-check-label', for: 'terms_of_service_agreement_checkbox' %>
109110
<%= link_to t('.view', default: 'View'), agreement_path(@terms_of_service_agreement, locale: I18n.locale), class: 'ms-2 agreement-modal-link', role: 'button', data: { agreement_identifier: 'terms_of_service' } %>
110-
<p id="terms-of-service-summary" class="form-text text-muted"><%= @terms_of_service_agreement.description %></p>
111+
<small id="terms-of-service-summary" class="form-text text-muted"><%= @terms_of_service_agreement.description %></small>
111112
</div>
112113
<% end %>
113114

114115
<% if @privacy_policy_agreement %>
115-
<div class="mb-3 form-check">
116-
<%= check_box_tag :privacy_policy_agreement, '1', false, class: 'form-check-input agreement-checkbox', data: { agreement_identifier: 'privacy_policy' }, required: true, aria: { describedby: 'privacy-policy-summary', disabled: 'true' } %>
117-
<%= label_tag :privacy_policy_agreement, t('.privacy_policy.label'), class: 'form-check-label' %>
116+
<div id="privacy-policy-agreement-group" class="mb-3 form-check agreement-group">
117+
<%= check_box_tag :privacy_policy_agreement, '1', false, class: 'form-check-input agreement-checkbox', data: { agreement_identifier: 'privacy_policy' }, required: true, aria: { describedby: 'privacy-policy-summary', disabled: 'true' }, id: 'privacy_policy_agreement_checkbox' %>
118+
<%= label_tag :privacy_policy_agreement, t('.privacy_policy.label'), class: 'form-check-label', for: 'privacy_policy_agreement_checkbox' %>
118119
<%= link_to t('.view', default: 'View'), agreement_path(@privacy_policy_agreement, locale: I18n.locale), class: 'ms-2 agreement-modal-link', role: 'button', data: { agreement_identifier: 'privacy_policy' } %>
119-
<p id="privacy-policy-summary" class="form-text text-muted"><%= @privacy_policy_agreement.description %></p>
120+
<small id="privacy-policy-summary" class="form-text text-muted"><%= @privacy_policy_agreement.description %></small>
120121
</div>
121122
<% end %>
122123

123124
<% if @code_of_conduct_agreement %>
124-
<div class="mb-3 form-check">
125-
<%= check_box_tag :code_of_conduct_agreement, '1', false, class: 'form-check-input agreement-checkbox', data: { agreement_identifier: 'code_of_conduct' }, required: true, aria: { describedby: 'code-of-conduct-summary', disabled: 'true' } %>
126-
<%= label_tag :code_of_conduct_agreement, t('.code_of_conduct.label'), class: 'form-check-label' %>
125+
<div id="code-of-conduct-agreement-group" class="mb-3 form-check agreement-group">
126+
<%= check_box_tag :code_of_conduct_agreement, '1', false, class: 'form-check-input agreement-checkbox', data: { agreement_identifier: 'code_of_conduct' }, required: true, aria: { describedby: 'code-of-conduct-summary', disabled: 'true' }, id: 'code_of_conduct_agreement_checkbox' %>
127+
<%= label_tag :code_of_conduct_agreement, t('.code_of_conduct.label'), class: 'form-check-label', for: 'code_of_conduct_agreement_checkbox' %>
127128
<%= link_to t('.view', default: 'View'), agreement_path(@code_of_conduct_agreement, locale: I18n.locale), class: 'ms-2 agreement-modal-link', role: 'button', data: { agreement_identifier: 'code_of_conduct' } %>
128-
<p id="code-of-conduct-summary" class="form-text text-muted"><%= @code_of_conduct_agreement.description %></p>
129+
<small id="code-of-conduct-summary" class="form-text text-muted"><%= @code_of_conduct_agreement.description %></small>
129130
</div>
130131
<% end %>
132+
</div>
131133
<% end %>
132134

133135
<!-- Host App Extensible Content (e.g., CAPTCHA, additional fields) -->
134136
<%= render partial: 'devise/registrations/extra_registration_fields', locals: { form: f, resource: resource } %>
135137

136138
<!-- Submit Button -->
137-
<div class="text-center">
138-
<%= f.submit t('.sign_up'), class: 'btn btn-primary' %>
139+
<div id="submit-section" class="text-center submit-section">
140+
<%= f.submit t('.sign_up'), class: 'btn btn-primary', id: 'registration-submit-btn' %>
139141
<!-- Additional Links -->
140-
<%= render "devise/shared/links" %>
142+
<div id="additional-links" class="additional-links">
143+
<%= render "devise/shared/links" %>
144+
</div>
141145
</div>
142146
<% end %>
143147
</div>

0 commit comments

Comments
 (0)