Skip to content

Commit

Permalink
Merge pull request #1613 from ministryofjustice/MLPAB-2461-errors
Browse files Browse the repository at this point in the history
MLPAB-2461 Associate errors to related input/fieldset
  • Loading branch information
hawx authored Nov 11, 2024
2 parents c48b2e6 + 9e21310 commit bb2716b
Show file tree
Hide file tree
Showing 57 changed files with 1,088 additions and 1,341 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ require (
golang.org/x/mod v0.22.0
golang.org/x/time v0.8.0
golang.org/x/tools v0.26.0
google.golang.org/appengine v1.6.8
)

require (
Expand All @@ -71,7 +70,6 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
Expand Down
131 changes: 0 additions & 131 deletions go.sum

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions internal/templatefn/fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func All(globals *Globals) map[string]any {
"lpaDecisions": lpaDecisions,
"summaryRow": summaryRow,
"staticSummaryRow": staticSummaryRow,
"legend": legend,
"legendHeading": legendHeading,
"fieldset": fieldset,
}
}

Expand Down Expand Up @@ -524,3 +527,40 @@ func staticSummaryRow(app appcontext.Data, label string, value any) map[string]a
"Static": true,
}
}

type legendData struct {
Label string
Classes string
H1 bool
}

func legend(label string, classes ...string) legendData {
return legendData{
Label: label,
Classes: strings.Join(classes, " "),
}
}

func legendHeading(label string, classes ...string) legendData {
return legendData{
Label: label,
Classes: strings.Join(classes, " "),
H1: true,
}
}

type fieldsetData struct {
Top any
Name string
Legend legendData
Items map[string]any
}

func fieldset(top any, name string, value any, legend legendData, is ...any) fieldsetData {
return fieldsetData{
Top: top,
Name: name,
Legend: legend,
Items: items(top, name, value, is...),
}
}
27 changes: 27 additions & 0 deletions internal/templatefn/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,30 @@ func TestStaticSummaryRow(t *testing.T) {
"Static": true,
}, staticSummaryRow(app, label, value))
}

func TestLegend(t *testing.T) {
assert.Equal(t, legendData{
Label: "a-label",
Classes: "class-1 class-2",
}, legend("a-label", "class-1", "class-2"))
}

func TestLegendHeading(t *testing.T) {
assert.Equal(t, legendData{
Label: "a-label",
Classes: "class-1 class-2",
H1: true,
}, legendHeading("a-label", "class-1", "class-2"))
}

func TestFieldset(t *testing.T) {
aLegend := legend("a-label")
anItem := item("a-value", "another-label")

assert.Equal(t, fieldsetData{
Top: "top",
Name: "a-name",
Legend: aLegend,
Items: items("top", "a-name", "a-value", anItem),
}, fieldset("top", "a-name", "a-value", aLegend, anItem))
}
190 changes: 96 additions & 94 deletions web/template/attorney/sign.gohtml
Original file line number Diff line number Diff line change
@@ -1,115 +1,117 @@
{{ template "page" . }}

{{ define "pageTitle" }}
{{ if .App.IsTrustCorporation }}
{{ tr .App "signOnBehalfOfTrustCorporation" }}
{{ else if .IsReplacement }}
{{ tr .App "signAsReplacementAttorney" }}
{{ else }}
{{ tr .App "signAsAttorney" }}
{{ end }}
{{ if .App.IsTrustCorporation }}
{{ tr .App "signOnBehalfOfTrustCorporation" }}
{{ else if .IsReplacement }}
{{ tr .App "signAsReplacementAttorney" }}
{{ else }}
{{ tr .App "signAsAttorney" }}
{{ end }}
{{ end }}

{{ define "main" }}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">
{{ template "pageTitle" . }}
</h1>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">
{{ template "pageTitle" . }}
</h1>

{{ if .App.IsTrustCorporation }}
{{ if .IsSecondSignatory }}
<p class="govuk-body">
<a href="{{ link .App (global.Paths.Attorney.WouldLikeSecondSignatory.Format .LpaID) }}" class="govuk-link">
{{ tr .App "theTrustCorporationNoLongerRequiresSecondSignatory" }}
</a>
</p>
{{ else }}
<p class="govuk-body">{{ tr .App "youCanChooseToAddSignatoryOnNextPage" }}</p>
{{ end }}
{{ end }}

{{ template "warning" (content .App "lpaCantBeRegisteredUntilAttorneysSign") }}
{{ if .App.IsTrustCorporation }}
{{ if .IsSecondSignatory }}
<p class="govuk-body">
<a href="{{ link .App (global.Paths.Attorney.WouldLikeSecondSignatory.Format .LpaID) }}" class="govuk-link">
{{ tr .App "theTrustCorporationNoLongerRequiresSecondSignatory" }}
</a>
</p>
{{ else }}
<p class="govuk-body">{{ tr .App "youCanChooseToAddSignatoryOnNextPage" }}</p>
{{ end }}
{{ end }}

<form novalidate method="post">
{{ if .App.IsTrustCorporation }}
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
{{ tr .App "authorisedSignatory" }}
</legend>
{{ template "warning" (content .App "lpaCantBeRegisteredUntilAttorneysSign") }}

{{ template "input" (input . "first-names" "firstNames" .Form.FirstNames "classes" "govuk-input--width-20" "hint" "firstNamesHint") }}
{{ template "input" (input . "last-name" "lastName" .Form.LastName "classes" "govuk-input--width-20") }}
{{ template "input" (input . "professional-title" "professionalTitle" .Form.ProfessionalTitle "hint" "professionalTitleHint" "classes" "govuk-input--width-20") }}
</fieldset>
{{ end }}
<form novalidate method="post">
{{ if .App.IsTrustCorporation }}
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
{{ tr .App "authorisedSignatory" }}
</legend>

<p class="govuk-body govuk-!-font-weight-bold">
{{ tr .App "bySigningIUnderstandAndConfirmAllOfTheFollowing" }}
</p>
{{ template "input" (input . "first-names" "firstNames" .Form.FirstNames "classes" "govuk-input--width-20" "hint" "firstNamesHint") }}
{{ template "input" (input . "last-name" "lastName" .Form.LastName "classes" "govuk-input--width-20") }}
{{ template "input" (input . "professional-title" "professionalTitle" .Form.ProfessionalTitle "hint" "professionalTitleHint" "classes" "govuk-input--width-20") }}
</fieldset>
{{ end }}

<ul class="govuk-list govuk-list--bullet">
{{ if .App.IsTrustCorporation }}
{{ trHtml .App "signAsTrustCorporationBullets" }}
{{ else }}
{{ trHtml .App "signAsAttorneyBullets" }}
{{ end }}
<li>
{{ if .LpaCanBeUsedWhenHasCapacity }}
{{ if .App.IsTrustCorporation }}
{{ tr .App "signAsTrustCorporationWhenRegisteredBullet" }}
{{ else }}
{{ tr .App "signAsAttorneyWhenRegisteredBullet" }}
{{ end }}
{{ else }}
{{ if .App.IsTrustCorporation }}
{{ tr .App "signAsTrustCorporationWhenCapacityLostBullet" }}
{{ else }}
{{ tr .App "signAsAttorneyWhenCapacityLostBullet" }}
{{ end }}
{{ end }}
</li>
</ul>

{{ if .IsReplacement }}
{{ if .App.IsTrustCorporation }}
{{ trFormatHtml .App "asReplacementTrustCorporationAlsoConfirmThat" "Name" .TrustCorporation.Name }}
{{ else }}
{{ trHtml .App "asReplacementAttorneyAlsoConfirmThat" }}
{{ end }}
{{ end }}
<p class="govuk-body govuk-!-font-weight-bold">
{{ tr .App "bySigningIUnderstandAndConfirmAllOfTheFollowing" }}
</p>

<div class="govuk-summary-card">
<div class="govuk-summary-card__title-wrapper">
<span class="govuk-summary-card__title">{{ tr .App "yourSignature" }}</span>
</div>
<div class="govuk-summary-card__content">
<div class="govuk-form-group govuk-!-margin-bottom-0 {{ if .Errors.Has "confirm" }}govuk-form-group--error{{ end }}">
{{ template "error-message" (errorMessage . "confirm") }}
<ul class="govuk-list govuk-list--bullet">
{{ if .App.IsTrustCorporation }}
{{ trHtml .App "signAsTrustCorporationBullets" }}
{{ else }}
{{ trHtml .App "signAsAttorneyBullets" }}
{{ end }}
<li>
{{ if .LpaCanBeUsedWhenHasCapacity }}
{{ if .App.IsTrustCorporation }}
{{ tr .App "signAsTrustCorporationWhenRegisteredBullet" }}
{{ else }}
{{ tr .App "signAsAttorneyWhenRegisteredBullet" }}
{{ end }}
{{ else }}
{{ if .App.IsTrustCorporation }}
{{ tr .App "signAsTrustCorporationWhenCapacityLostBullet" }}
{{ else }}
{{ tr .App "signAsAttorneyWhenCapacityLostBullet" }}
{{ end }}
{{ end }}
</li>
</ul>

<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="f-confirm" name="confirm" type="checkbox" value="1" {{ if .Form.Confirm }}checked{{ end }}>
<label class="govuk-label govuk-checkboxes__label" for="f-confirm">
{{ if .IsReplacement }}
{{ if .App.IsTrustCorporation }}
{{ trFormat .App "iTrustCorporationConfirmTheseStatements" "TrustCorporationName" .TrustCorporation.Name }}
{{ trFormatHtml .App "asReplacementTrustCorporationAlsoConfirmThat" "Name" .TrustCorporation.Name }}
{{ else }}
{{ trFormat .App "iAttorneyConfirmTheseStatements" "AttorneyFullName" .Attorney.FullName }}
{{ trHtml .App "asReplacementAttorneyAlsoConfirmThat" }}
{{ end }}
</label>
{{ end }}

<div class="govuk-summary-card">
<div class="govuk-summary-card__title-wrapper">
<span id="fieldset-legend" class="govuk-summary-card__title">{{ tr .App "yourSignature" }}</span>
</div>
<div class="govuk-summary-card__content">
<div class="govuk-form-group govuk-!-margin-bottom-0 {{ if .Errors.Has "confirm" }}govuk-form-group--error{{ end }}">
<fieldset class="govuk-fieldset" aria-labelledby="fieldset-legend" {{ if .Errors.Has "confirm" }}aria-describedby="confirm-error"{{ end }}>
{{ template "error-message" (errorMessage . "confirm") }}

<div class="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="f-confirm" name="confirm" type="checkbox" value="1" {{ if .Form.Confirm }}checked{{ end }}>
<label class="govuk-label govuk-checkboxes__label" for="f-confirm">
{{ if .App.IsTrustCorporation }}
{{ trFormat .App "iTrustCorporationConfirmTheseStatements" "TrustCorporationName" .TrustCorporation.Name }}
{{ else }}
{{ trFormat .App "iAttorneyConfirmTheseStatements" "AttorneyFullName" .Attorney.FullName }}
{{ end }}
</label>
</div>
</div>
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="govuk-button-group">
<button type="submit" class="govuk-button" data-module="govuk-button">{{ tr .App "submitSignature" }}</button>
<a href="{{ link .App (global.Paths.Attorney.ConfirmDontWantToBeAttorney.Format .LpaID) }}" class="govuk-button govuk-button--warning" data-module="govuk-button">{{ tr .App "iDoNotWantToBeAttorney" }}</a>
<div class="govuk-button-group">
<button type="submit" class="govuk-button" data-module="govuk-button">{{ tr .App "submitSignature" }}</button>
<a href="{{ link .App (global.Paths.Attorney.ConfirmDontWantToBeAttorney.Format .LpaID) }}" class="govuk-button govuk-button--warning" data-module="govuk-button">{{ tr .App "iDoNotWantToBeAttorney" }}</a>
</div>

{{ template "csrf-field" . }}
</form>
</div>

{{ template "csrf-field" . }}
</form>
</div>
</div>
{{ end }}
31 changes: 11 additions & 20 deletions web/template/attorney/would_like_second_signatory.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@
{{ define "pageTitle" }}{{ tr .App "wouldYouLikeToAddSecondSignatory" }}{{ end }}

{{ define "main" }}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form novalidate method="post">
<div class="govuk-form-group {{ if .Errors.Has .Form.FieldName }}govuk-form-group--error{{ end }}">
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">{{ tr .App "wouldYouLikeToAddSecondSignatory" }}</h1>
</legend>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form novalidate method="post">
{{ template "radios-fieldset" (fieldset . .Form.FieldName .Form.YesNo.String
(legendHeading "wouldYouLikeToAddSecondSignatory" "govuk-fieldset__legend--xl")
(item .Form.Options.Yes.String "yesByddwn")
(item .Form.Options.No.String "noNaFyddwn")
) }}

{{ template "error-message" (errorMessage . .Form.FieldName) }}

{{ template "radios" (items . .Form.FieldName .Form.YesNo.String
(item .Form.Options.Yes.String "yesByddwn")
(item .Form.Options.No.String "noNaFyddwn")
) }}
</fieldset>
{{ template "continue-button" . }}
{{ template "csrf-field" . }}
</form>
</div>

{{ template "continue-button" . }}
{{ template "csrf-field" . }}
</form>
</div>
</div>
{{ end }}
Loading

0 comments on commit bb2716b

Please sign in to comment.