Skip to content

Commit

Permalink
Merge pull request #430 from hmrc/DL-12580
Browse files Browse the repository at this point in the history
Fix accessibility issues for multiple date inputs on 1 page Dl 12580
  • Loading branch information
benryan1790 authored May 20, 2024
2 parents 3a5c602 + d91f59b commit 23eb8d7
Show file tree
Hide file tree
Showing 9 changed files with 402 additions and 233 deletions.
50 changes: 21 additions & 29 deletions app/views/editLiability/editLiabilityDatesLiable.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import models._
@import play.twirl.api.HtmlFormat
@import uk.gov.hmrc.govukfrontend.views.html.components._
@import views.html.helpers._
@import views.ViewUtils.titleBuilder
@import models.StringFormatting._

Expand Down Expand Up @@ -47,13 +48,6 @@
}
}

@dateItems = @{
Seq(InputItem(attributes = Map("maxLength" -> "2")),
InputItem(attributes = Map("maxLength" -> "2")),
InputItem(attributes = Map("maxLength" -> "4"))
)
}

@newMain(title = titleBuilder(messages("ated.property-details-period.change-dates-liable.title"),Some(propertyDetailsForm)), serviceInfoContent = serviceInfoContent) {

@backLinkHtml
Expand All @@ -76,29 +70,27 @@ <h1 class="govuk-heading-xl govuk-!-margin-bottom-5">

@formHelper(action = controllers.editLiability.routes.EditLiabilityDatesLiableController.save(formBundleNo, periodKey)) {

@govukDateInput(DateInput(
hint = Some(Hint(
content = Text(messages("ated.property-details-period.datesLiable.startDate.hint", periodStartDate(periodKey).toString(messages("ated.date-format.numeric"))))
)),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("ated.property-details-period.change-dates-liable.startDate"))
))
)),
items = dateItems
).withFormField(propertyDetailsForm("startDate")))
@dateInput(
field = "startDate",
legend = "ated.property-details-period.change-dates-liable.startDate",
hint = "ated.property-details-period.datesInRelief.startDate.hint",
dayHidden = "ated.property-details-period.change-dates-liable.startDate.hiddenContentDay",
monthHidden = "ated.property-details-period.change-dates-liable.startDate.hiddenContentMonth",
yearHidden = "ated.property-details-period.change-dates-liable.startDate.hiddenContentYear",
periodKey = periodKey,
form = propertyDetailsForm
)

@govukDateInput(DateInput(
hint = Some(Hint(
content = Text(messages("ated.property-details-period.datesLiable.endDate.hint", periodEndDate(periodKey).toString(messages("ated.date-format.numeric"))))
)),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("ated.property-details-period.change-dates-liable.endDate"))
))
)),
items = dateItems
).withFormField(propertyDetailsForm("endDate")))
@dateInput(
field = "endDate",
legend = "ated.property-details-period.change-dates-liable.endDate",
hint = "ated.property-details-period.datesInRelief.startDate.hint",
dayHidden = "ated.property-details-period.change-dates-liable.endDate.hiddenContentDay",
monthHidden = "ated.property-details-period.change-dates-liable.endDate.hiddenContentMonth",
yearHidden = "ated.property-details-period.change-dates-liable.endDate.hiddenContentYear",
periodKey = periodKey,
form = propertyDetailsForm
)

@govukButton(Button(
content = Text(messages("ated.save-and-continue")),
Expand Down
119 changes: 119 additions & 0 deletions app/views/helpers/dateInput.scala.html
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>
65 changes: 25 additions & 40 deletions app/views/propertyDetails/periodDatesLiable.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@
* limitations under the License.
*@

@import models._
@import _root_.utils._
@import config.ApplicationConfig
@import models._
@import play.twirl.api.HtmlFormat
@import uk.gov.hmrc.govukfrontend.views.html.components._
@import uk.gov.hmrc.govukfrontend.views.html.components.implicits._
@import views.ViewUtils.titleBuilder
@import views.html.helpers._
@import _root_.utils._
@import models.StringFormatting._


@this(newMain: newMain,
govukButton : GovukButton,
govukBackLink : GovukBackLink,
govukDateInput : GovukDateInput,
govukErrorSummary : GovukErrorSummary,
formHelper: FormWithCSRF)
govukErrorSummary : GovukErrorSummary,
formHelper: FormWithCSRF)

@(id: String, periodKey: Int, propertyDetailsForm: Form[PropertyDetailsDatesLiable], title: String, mode: Option[String], serviceInfoContent: Html = HtmlFormat.empty, backLink: Option[String])(implicit authContext: StandardAuthRetrievals, messages: Messages, request: Request[AnyContent], appConfig: ApplicationConfig)

Expand All @@ -43,13 +41,6 @@
}
}

@dateItems = @{
Seq(InputItem(attributes = Map("maxLength" -> "2")),
InputItem(attributes = Map("maxLength" -> "2")),
InputItem(attributes = Map("maxLength" -> "4"))
)
}

@pageHeader = @{title}

@newMain(title = titleBuilder(messages(title), Some(propertyDetailsForm)),
Expand All @@ -75,33 +66,27 @@ <h1 class="govuk-heading-xl govuk-!-margin-bottom-5">

@formHelper(action=controllers.propertyDetails.routes.PeriodDatesLiableController.save(id, periodKey, mode)) {

@govukDateInput(DateInput(
hint = Some(Hint(
content = Text(messages("ated.property-details-period.datesInRelief.startDate.hint",
PeriodUtils.periodStartDate(periodKey).toString(messages("ated.date-format.numeric"))))
)),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("ated.property-details-period.datesLiable.startDate")),
classes = "govuk-label--s"
))
)),
items = dateItems
).withFormField(propertyDetailsForm("startDate")))

@govukDateInput(DateInput(
hint = Some(Hint(
content = Text(messages("ated.property-details-period.datesInRelief.endDate.hint",
PeriodUtils.periodEndDate(periodKey).toString(messages("ated.date-format.numeric"))))
)),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("ated.property-details-period.datesLiable.endDate")),
classes = "govuk-label--s"
))
)),
items = dateItems
).withFormField(propertyDetailsForm("endDate")))
@dateInput(
field = "startDate",
legend = "ated.property-details-period.datesLiable.startDate",
hint = "ated.property-details-period.datesInRelief.startDate.hint",
dayHidden = "ated.property-details-period.datesLiable.startDate.hiddenContentDay",
monthHidden = "ated.property-details-period.datesLiable.startDate.hiddenContentMonth",
yearHidden = "ated.property-details-period.datesLiable.startDate.hiddenContentYear",
periodKey = periodKey,
form = propertyDetailsForm
)

@dateInput(
field = "endDate",
legend = "ated.property-details-period.datesLiable.endDate",
hint = "ated.property-details-period.datesInRelief.endDate.hint",
dayHidden = "ated.property-details-period.datesLiable.endDate.hiddenContentDay",
monthHidden = "ated.property-details-period.datesLiable.endDate.hiddenContentMonth",
yearHidden = "ated.property-details-period.datesLiable.endDate.hiddenContentYear",
periodKey = periodKey,
form = propertyDetailsForm
)

@govukButton(Button(
content = Text(messages("ated.save-and-continue")),
Expand Down
56 changes: 21 additions & 35 deletions app/views/propertyDetails/periodInReliefDates.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@
}
}

@dateItems = @{
Seq(InputItem(attributes = Map("maxLength" -> "2")),
InputItem(attributes = Map("maxLength" -> "2")),
InputItem(attributes = Map("maxLength" -> "4"))
)
}


@newMain(title = titleBuilder(messages("ated.property-details-period.datesInRelief.title"), Some(propertyDetailsForm)),
serviceInfoContent = serviceInfoContent) {

Expand All @@ -77,33 +69,27 @@ <h1 class="govuk-heading-xl govuk-!-margin-bottom-5">

@formHelper(action=controllers.propertyDetails.routes.PeriodInReliefDatesController.save(id, periodKey)) {

@govukDateInput(DateInput(
hint = Some(Hint(
content = Text(messages("ated.property-details-period.datesInRelief.startDate.hint",
PeriodUtils.periodStartDate(periodKey).toString(messages("ated.date-format.numeric"))))
)),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("ated.property-details-period.datesInRelief.startDate")),
classes = "govuk-label--s"
))
)),
items = dateItems
).withFormField(propertyDetailsForm("startDate")))

@govukDateInput(DateInput(
hint = Some(Hint(
content = Text(messages("ated.property-details-period.datesInRelief.endDate.hint",
PeriodUtils.periodEndDate(periodKey).toString(messages("ated.date-format.numeric"))))
)),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("ated.property-details-period.datesInRelief.endDate")),
classes = "govuk-label--s"
))
)),
items = dateItems
).withFormField(propertyDetailsForm("endDate")))
@dateInput(
field = "startDate",
legend = "ated.property-details-period.datesInRelief.startDate",
hint = "ated.property-details-period.datesInRelief.startDate.hint",
dayHidden = "ated.property-details-period.datesInRelief.startDate.hiddenContentDay",
monthHidden = "ated.property-details-period.datesInRelief.startDate.hiddenContentMonth",
yearHidden = "ated.property-details-period.datesInRelief.startDate.hiddenContentYear",
periodKey = periodKey,
form = propertyDetailsForm
)

@dateInput(
field = "endDate",
legend = "ated.property-details-period.datesInRelief.endDate",
hint = "ated.property-details-period.datesInRelief.endDate.hint",
dayHidden = "ated.property-details-period.datesInRelief.endDate.hiddenContentDay",
monthHidden = "ated.property-details-period.datesInRelief.endDate.hiddenContentMonth",
yearHidden = "ated.property-details-period.datesInRelief.endDate.hiddenContentYear",
periodKey = periodKey,
form = propertyDetailsForm
)

@govukButton(Button(
content = Text(messages("ated.save-and-continue")),
Expand Down
Loading

0 comments on commit 23eb8d7

Please sign in to comment.