diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-06-29 15:00:55 +0100 |
---|---|---|
committer | M Somerville <matthew-github@dracos.co.uk> | 2020-11-11 10:28:23 +0000 |
commit | ce1b3ec61fdaa954c26e55b8ce8cd1ad619b3538 (patch) | |
tree | 3ab20e43f6bf6b4a0ca1284c019a26f5fe7a2ef5 /perllib/FixMyStreet/App/Form/Field/Postcode.pm | |
parent | 9292866fbc1be364a716ac9efb105a0350a2de72 (diff) |
[Bromley] Add waste service lookup.
This creates an integration to view bin collection days, and
placeholders for the start of a non-map property-based reporting flow.
Diffstat (limited to 'perllib/FixMyStreet/App/Form/Field/Postcode.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Form/Field/Postcode.pm | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Form/Field/Postcode.pm b/perllib/FixMyStreet/App/Form/Field/Postcode.pm new file mode 100644 index 000000000..093ae66a3 --- /dev/null +++ b/perllib/FixMyStreet/App/Form/Field/Postcode.pm @@ -0,0 +1,50 @@ +package FixMyStreet::App::Form::Field::Postcode; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler::Field::Text'; + +use mySociety::PostcodeUtil; + +apply( + [ + { + transform => sub { + my ( $value, $field ) = @_; + $value =~ s/[^A-Z0-9]//i; + return mySociety::PostcodeUtil::canonicalise_postcode($value); + } + }, + { + check => sub { mySociety::PostcodeUtil::is_valid_postcode(shift) }, + message => 'Sorry, we did not recognise that postcode.', + } + ] +); + + +__PACKAGE__->meta->make_immutable; +use namespace::autoclean; + +1; + +__END__ + +=pod + +=encoding UTF-8 + +=head1 NAME + +FixMyStreet::App::Form::Field::Postcode - validates postcode using mySociety::PostcodeUtil + +=head1 DESCRIPTION + +Validates that the input looks like a postcode using L<mySociety::PostcodeUtil>. +Widget type is 'text'. + +=head1 DEPENDENCIES + +L<mySociety::PostcodeUtil> + +=cut + |