From ce1b3ec61fdaa954c26e55b8ce8cd1ad619b3538 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 29 Jun 2020 15:00:55 +0100 Subject: [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. --- perllib/FixMyStreet/App/Form/Field/Postcode.pm | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 perllib/FixMyStreet/App/Form/Field/Postcode.pm (limited to 'perllib/FixMyStreet/App/Form/Field/Postcode.pm') 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. +Widget type is 'text'. + +=head1 DEPENDENCIES + +L + +=cut + -- cgit v1.2.3