Skip to content

Commit 8b5aef9

Browse files
authored
Merge pull request #112 from companieshouse/feature/show-warnings
Display warnings
2 parents 7501900 + afb2a34 commit 8b5aef9

File tree

4 files changed

+57
-20
lines changed

4 files changed

+57
-20
lines changed

lib/ChGovUk/Plugins/FormHelpers.pm

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ has 'controller';
1212
has 'model';
1313
has 'labels' => sub { {} };
1414
has 'errors' => sub { [] };
15+
has 'warnings' => sub { [] };
1516
has 'blocks' => sub { [] };
1617

1718
# ========================================================| MOJO INTERFACE |====
@@ -45,6 +46,16 @@ sub errors_count {
4546

4647
# -----------------------------------------------------------------------------
4748

49+
sub warnings_count {
50+
my ($self) = @_;
51+
52+
my $count = scalar @{ $self->warnings };
53+
trace "There are %s warnings", $count [VALIDATION];
54+
return $count;
55+
}
56+
57+
# -----------------------------------------------------------------------------
58+
4859
sub _render_template {
4960
my ($self, $args) = @_;
5061

@@ -484,18 +495,23 @@ sub _get_errors_for_field {
484495
}
485496

486497
$error = Locale::Simple::l($error, { %error_args } );
487-
my $error_id = $self->_field_name_to_id($field) . '-' . $rule . '-error';
488-
push @errors, { text => $error, id => $error_id };
489498

490499
# Add error to global error array
491500
my %error_hash;
492501
$error_hash{name} = $field;
493502
$error_hash{text} = $error;
494503

495-
# Does the controller have a corresponding field?
496-
if ( defined $self->labels->{$field} ) {
497-
$error_hash{id} = $error_id;
498-
push $self->errors, \%error_hash;
504+
if ($self->_is_warning($rule)) {
505+
push @{$self->warnings}, \%error_hash;
506+
} else {
507+
my $error_id = $self->_field_name_to_id($field) . '-' . $rule . '-error';
508+
push @errors, { text => $error, id => $error_id };
509+
510+
# Does the controller have a corresponding field?
511+
if (defined $self->labels->{$field} ) {
512+
$error_hash{id} = $error_id;
513+
push @{$self->errors}, \%error_hash;
514+
}
499515
}
500516
}
501517
}
@@ -656,6 +672,13 @@ sub _field_name_to_id {
656672

657673
# -----------------------------------------------------------------------------
658674

675+
sub _is_warning {
676+
my ($self, $rule) = @_;
677+
return $rule eq "etag-mismatch";
678+
}
679+
680+
# -----------------------------------------------------------------------------
681+
659682

660683
1;
661684

templates/company/transactions/change_registered_office_address.html.tx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<legend class="heading-medium text">What is the new address of the company?</legend>
99
% $c.include_later('includes/forms/errors', form => $form, form_title => 'Filing Error');
1010
% include 'includes/forms/address.tx' { form => $form, name => 'address', include_po_box => 1 }
11+
% $form.hidden_field( name => 'address[etag]', value => $etag );
1112
</fieldset>
1213
% }

templates/company/transactions/current_address.html.tx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<p class="text">
2-
% $form.hidden_field( name => 'address[etag]', value => $etag );
32
Current address
43
<br />
54
% if $care_of_name {
Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
% if $form.model && $form.errors_count() > 0 {
2-
<div class="error-summary" role="group" tabindex="-1">
3-
<h2 class="heading-medium error-summary-heading">
4-
<% $form_title %>
5-
</h2>
6-
<p>
7-
This form has errors
8-
</p>
9-
<ul class="error-summary-list">
10-
% for $form.errors -> $error {
11-
<li><a href="#<% $error.id %>"><% $error.text %></a></li>
1+
% if $form.model {
2+
% if $form.warnings_count() > 0 {
3+
% for $form.warnings -> $warning {
4+
<div class="govuk-warning-text">
5+
<span class="govuk-warning-text__icon" aria-hidden="true">!</span>
6+
<strong class="govuk-warning-text__text">
7+
<span class="govuk-warning-text__assistive">Warning</span>
8+
<% $warning.text %>
9+
</strong>
10+
</div>
1211
% }
13-
</ul>
14-
</div>
12+
% }
13+
14+
% if $form.errors_count() > 0 {
15+
<div class="error-summary" role="group" tabindex="-1">
16+
<h2 class="heading-medium error-summary-heading">
17+
<% $form_title %>
18+
</h2>
19+
<p>
20+
This form has errors
21+
</p>
22+
<ul class="error-summary-list">
23+
% for $form.errors -> $error {
24+
<li><a href="#<% $error.id %>"><% $error.text %></a></li>
25+
% }
26+
</ul>
27+
</div>
28+
% }
1529
% }

0 commit comments

Comments
 (0)