-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2379 from DFE-Digital/ghana-validation-number
Add teacher license form for Ghana
- Loading branch information
Showing
19 changed files
with
665 additions
and
10 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
57 changes: 57 additions & 0 deletions
57
app/forms/teacher_interface/ghana_registration_number_form.rb
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,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module TeacherInterface | ||
class GhanaRegistrationNumberForm < BaseForm | ||
attr_accessor :application_form | ||
|
||
attribute :registration_number, :string | ||
attribute :license_number_part_one, :string | ||
attribute :license_number_part_two, :string | ||
attribute :license_number_part_three, :string | ||
|
||
validates :application_form, presence: true | ||
|
||
validate :license_number_parts_valid | ||
|
||
def initialize(attributes = {}) | ||
super | ||
|
||
if attributes[:registration_number].present? | ||
license_number_parts = attributes[:registration_number].split("/") | ||
|
||
self.license_number_part_one = license_number_parts[0] | ||
self.license_number_part_two = license_number_parts[1] | ||
self.license_number_part_three = license_number_parts[2] | ||
end | ||
end | ||
|
||
def update_model | ||
application_form.update!(registration_number:) | ||
end | ||
|
||
def registration_number_validator | ||
@registration_number_validator ||= | ||
RegistrationNumberValidators::Ghana.new(registration_number:) | ||
end | ||
|
||
private | ||
|
||
def license_number_parts_valid | ||
return if registration_number_validator.valid? | ||
|
||
errors.add(:registration_number, :invalid) | ||
end | ||
|
||
def registration_number | ||
registration_number_parts = [ | ||
license_number_part_one, | ||
license_number_part_two, | ||
license_number_part_three, | ||
].map(&:strip) | ||
|
||
return nil if registration_number_parts.compact_blank.empty? | ||
|
||
registration_number_parts.join("/") | ||
end | ||
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
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 @@ | ||
# frozen_string_literal: true | ||
|
||
module RegistrationNumberValidators | ||
class Ghana | ||
def initialize(registration_number:) | ||
@registration_number = registration_number | ||
|
||
registration_number_parts = registration_number.to_s.split("/") | ||
|
||
@license_number_part_one = registration_number_parts[0] | ||
@license_number_part_two = registration_number_parts[1] | ||
@license_number_part_three = registration_number_parts[2] | ||
end | ||
|
||
def valid? | ||
license_number_part_one_valid? && license_number_part_two_valid? && | ||
license_number_part_three_valid? | ||
end | ||
|
||
def license_number_part_one_valid? | ||
license_number_part_one.to_s.length == 2 && | ||
license_number_part_one.match?(/\A[a-zA-Z]*\z/) | ||
end | ||
|
||
def license_number_part_two_valid? | ||
license_number_part_two.to_s.length == 6 && | ||
license_number_part_two.match?(/^[0-9]+$/) | ||
end | ||
|
||
def license_number_part_three_valid? | ||
license_number_part_three.to_s.length == 4 && | ||
license_number_part_three.match?(/^[0-9]+$/) | ||
end | ||
|
||
private | ||
|
||
attr_reader :license_number_part_one, | ||
:license_number_part_two, | ||
:license_number_part_three | ||
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
2 changes: 1 addition & 1 deletion
2
app/views/shared/application_form/_registration_number_summary.html.erb
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
77 changes: 77 additions & 0 deletions
77
app/views/teacher_interface/registration_number/edit_ghana.html.erb
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,77 @@ | ||
<% content_for :page_title, title_with_error_prefix(t("application_form.tasks.items.registration_number.ghana"), error: @form.errors.any?) %> | ||
<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_path) %> | ||
|
||
<%= form_with model: @form, url: %i[registration_number teacher_interface application_form] do |f| %> | ||
<%= f.govuk_error_summary %> | ||
|
||
<div class="govuk-form-group <%= 'govuk-form-group--error' if @form.errors.present? %>"> | ||
<fieldset class="govuk-fieldset" aria-describedby="teacher-interface-ghana-registration-number-form-registration-number-hint"> | ||
<h1 class="govuk-label-wrapper"> | ||
<label for="teacher-interface-ghana-registration-number-form-registration-number-field" class="govuk-label govuk-label--l"> | ||
<%= t("helpers.label.teacher_interface_ghana_registration_number_form.registration_number") %> | ||
</label> | ||
</h1> | ||
<div class="govuk-hint" id="teacher-interface-ghana-registration-number-form-registration-number-hint"> | ||
<%= t("helpers.hint.teacher_interface_ghana_registration_number_form.registration_number") %> | ||
</div> | ||
|
||
<% if @form.errors.present? %> | ||
<p id="teacher-interface-ghana-registration-number-form-registration-number-field-error" class="govuk-error-message"> | ||
<span class="govuk-visually-hidden">Error:</span> | ||
<%= @form.errors.first.message %> | ||
</p> | ||
<% end %> | ||
|
||
<div class="govuk-date-input"> | ||
<div class="govuk-date-input__item"> | ||
<div class="govuk-form-group"> | ||
<input id="teacher-interface-ghana-registration-number-form-license-number-part-one" | ||
class="govuk-input govuk-date-input__input govuk-input--width-2 <%= 'govuk-input--error' if @form.errors.present? && !@form.registration_number_validator.license_number_part_one_valid? %>" | ||
name="teacher_interface_ghana_registration_number_form[license_number_part_one]" | ||
type="text" inputmode="text" value=<%= @form.license_number_part_one %>> | ||
</div> | ||
</div> | ||
<div class="govuk-date-input__item"> | ||
<div class="govuk-form-group"> | ||
<input id="teacher-interface-ghana-registration-number-form-license-number-part-two" | ||
class="govuk-input govuk-date-input__input govuk-input--width-4 <%= 'govuk-input--error' if @form.errors.present? && !@form.registration_number_validator.license_number_part_two_valid? %>" | ||
name="teacher_interface_ghana_registration_number_form[license_number_part_two]" | ||
type="text" | ||
inputmode="numeric" | ||
value=<%= @form.license_number_part_two %>> | ||
</div> | ||
</div> | ||
<div class="govuk-date-input__item"> | ||
<div class="govuk-form-group"> | ||
<input id="teacher-interface-ghana-registration-number-form-license-number-part-three" | ||
class="govuk-input govuk-date-input__input govuk-input--width-3 <%= 'govuk-input--error' if @form.errors.present? && !@form.registration_number_validator.license_number_part_three_valid? %>" | ||
name="teacher_interface_ghana_registration_number_form[license_number_part_three]" | ||
type="text" | ||
inputmode="numeric" | ||
value=<%= @form.license_number_part_three %>> | ||
</div> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</div> | ||
|
||
<div class="govuk-!-padding-bottom-3"></div> | ||
|
||
<h2 class="govuk-heading-m">Finding and checking your teacher license number</h2> | ||
<p class="govuk-body"> | ||
You can get your teacher license number by signing in to your <%= link_to "Teacher Portal Ghana account", "https://tpg.ntc.gov.gh/account/login/teacher" %>.</p> | ||
<p class="govuk-body">You can check your number on the <%= link_to "Teacher Portal Ghana website", "https://tpg.ntc.gov.gh/public/teacher/verify-license" %>.</p> | ||
<p class="govuk-body">If you cannot find your teaching license number, contact the <%= link_to "Ghana National Teaching Council", "https://ntc.gov.gh/" %>.</p> | ||
|
||
<div class="govuk-!-padding-bottom-3"></div> | ||
|
||
<h2 class="govuk-heading-m">Why we need your teacher license number</h2> | ||
<p class="govuk-body"> | ||
We use this number to verify you are registered to teach in Ghana. | ||
If you do not have one, we will not be able to verify you. This means your application will be declined. We do not accept other registration or license numbers. | ||
</p> | ||
|
||
<div class="govuk-!-padding-bottom-3"></div> | ||
|
||
<%= render "shared/save_submit_buttons", f: %> | ||
<% 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
Oops, something went wrong.