-
Notifications
You must be signed in to change notification settings - Fork 7
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 #430 from hmrc/DL-12580
Fix accessibility issues for multiple date inputs on 1 page Dl 12580
- Loading branch information
Showing
9 changed files
with
402 additions
and
233 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
@* | ||
* Copyright 2024 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*@ | ||
|
||
@import _root_.utils._ | ||
@import models.StringFormatting._ | ||
@import play.twirl.api.HtmlFormat | ||
|
||
@( | ||
field: String, | ||
legend: String, | ||
hint: String, | ||
dayHidden: String, | ||
monthHidden: String, | ||
yearHidden: String, | ||
periodKey: Int, | ||
form: Form[_])(implicit messages: Messages) | ||
|
||
@formGroupErrorClass() = @{ | ||
if(form.errors.exists(_.key.contains(field))) { | ||
"govuk-form-group govuk-form-group--error" | ||
} else { | ||
"govuk-form-group" | ||
} | ||
} | ||
|
||
@fieldLevelErrorClass(dateField: String) = @{ | ||
val num = if(dateField == "year") "4" else "2" | ||
if(form.errors.exists(er => er.key == field || (er.key.startsWith(field) && er.message.toLowerCase.contains(dateField)))) { | ||
s"govuk-input govuk-date-input__input govuk-input--width-$num govuk-input--error" | ||
} else { | ||
s"govuk-input govuk-date-input__input govuk-input--width-$num" | ||
} | ||
} | ||
|
||
@fieldLevelErrorMessage() = @{ | ||
val message = form.errors.collect { | ||
case e if e.key.startsWith(field) => | ||
e.format | ||
} | ||
|
||
if(message.nonEmpty) { | ||
Html( | ||
s"""<p id="$field-error" class="govuk-error-message"> | ||
| <span class="govuk-visually-hidden">Error:</span> ${message.head} | ||
| </p>""".stripMargin | ||
) | ||
} else HtmlFormat.empty | ||
} | ||
|
||
|
||
@ariaDescribedby() = @{ | ||
form.errors.filter(_.key.contains(field)) match { | ||
case x :: _ => s"$field-hint $field-error" | ||
case Nil => s"$field-hint" | ||
} | ||
} | ||
|
||
@fieldValue(value: String) = @{ | ||
form(value).value.map(x => s"value=$x") | ||
} | ||
|
||
@id(dateField: String) = @{ | ||
s"$field.$dateField" | ||
} | ||
|
||
<div class="@formGroupErrorClass()"> | ||
<fieldset class="govuk-fieldset" role="group" aria-describedby="@ariaDescribedby()"> | ||
<legend class="govuk-fieldset__legend govuk-fieldset__legend--s"> | ||
@messages(legend) | ||
</legend> | ||
<div id="@field-hint" class="govuk-hint"> | ||
@messages(hint, PeriodUtils.periodStartDate(periodKey).toString(messages("ated.date-format.numeric"))) | ||
</div> | ||
|
||
@fieldLevelErrorMessage() | ||
<div class="govuk-date-input" id=@field> | ||
<div class="govuk-date-input__item"> | ||
<div class="govuk-form-group"> | ||
<label class="govuk-label govuk-date-input__label" for=@id("day")> | ||
<span aria-hidden="true">Day</span> | ||
<span class="govuk-visually-hidden">@messages(dayHidden)</span> | ||
</label> | ||
<input class="@fieldLevelErrorClass("day")" id=@id("day") name=@id("day") type="text" inputmode="numeric" @fieldValue(s"$field.day")> | ||
</div> | ||
</div> | ||
<div class="govuk-date-input__item"> | ||
<div class="govuk-form-group"> | ||
<label class="govuk-label govuk-date-input__label" for=@id("month")> | ||
<span aria-hidden="true">Month</span> | ||
<span class="govuk-visually-hidden">@messages(monthHidden)</span> | ||
</label> | ||
<input class="@fieldLevelErrorClass("month")" id=@id("month") name=@id("month") type="text" inputmode="numeric" @fieldValue(s"$field.month")> | ||
</div> | ||
</div> | ||
<div class="govuk-date-input__item"> | ||
<div class="govuk-form-group"> | ||
<label class="govuk-label govuk-date-input__label" for=@id("year")> | ||
<span aria-hidden="true">Year</span> | ||
<span class="govuk-visually-hidden">@messages(yearHidden)</span> | ||
</label> | ||
<input class="@fieldLevelErrorClass("year")" id=@id("year") name=@id("year") type="text" inputmode="numeric" @fieldValue(s"$field.year")> | ||
</div> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</div> |
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.