Add patern data entry to location number
This commit is contained in:
parent
8ea5c077c0
commit
b6ecbb61c2
@ -0,0 +1,43 @@
|
||||
import React, { Fragment } from 'react';
|
||||
|
||||
import { BaseDataEntryProps } from './data-entry';
|
||||
import { DataTitleCopyable } from './data-title';
|
||||
|
||||
|
||||
interface PatternDataEntryProps extends BaseDataEntryProps {
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
/**
|
||||
* This is not a JS RegExp, so there's no validation in code, because we're passing it to HTML input as a string
|
||||
*/
|
||||
pattern: string;
|
||||
maxLength?: number;
|
||||
}
|
||||
|
||||
export const PatternDataEntry: React.FC<PatternDataEntryProps> = props => {
|
||||
const handleChange = (value: string) => {
|
||||
props.onChange?.(props.slug, value);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<DataTitleCopyable
|
||||
slug={props.slug}
|
||||
slugModifier={props.slugModifier}
|
||||
title={props.title}
|
||||
tooltip={props.tooltip}
|
||||
disabled={props.disabled || props.value == undefined || props.value == ''}
|
||||
copy={props.copy}
|
||||
/>
|
||||
<input className="form-control" type={props.isUrl? "url" : "text"}
|
||||
value={props.value || ''}
|
||||
required={props.required}
|
||||
disabled={props.mode === 'view' || props.disabled}
|
||||
placeholder={props.placeholder}
|
||||
pattern={props.pattern}
|
||||
maxLength={props.maxLength}
|
||||
onChange={e => handleChange(e.target.value)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
@ -7,9 +7,12 @@ import NumericDataEntry from '../data-components/numeric-data-entry';
|
||||
import UPRNsDataEntry from '../data-components/uprns-data-entry';
|
||||
import Verification from '../data-components/verification';
|
||||
import withCopyEdit from '../data-container';
|
||||
import { PatternDataEntry } from '../data-components/pattern-data-entry';
|
||||
|
||||
import { CategoryViewProps } from './category-view-props';
|
||||
|
||||
const locationNumberPattern = "[1-9]\\d*[a-z]?(-([1-9]\\d*))?"; ///[1-9]\d*[a-z]?(-([1-9]\d*))?/;
|
||||
|
||||
const LocationView: React.FunctionComponent<CategoryViewProps> = (props) => (
|
||||
<Fragment>
|
||||
<InfoBox msg="Text-based address fields are disabled at the moment. We're looking into how best to collect this data." />
|
||||
@ -33,15 +36,15 @@ const LocationView: React.FunctionComponent<CategoryViewProps> = (props) => (
|
||||
verified_count={props.building.verified.location_name}
|
||||
/>
|
||||
|
||||
<NumericDataEntry
|
||||
<PatternDataEntry
|
||||
title={dataFields.location_number.title}
|
||||
slug="location_number"
|
||||
value={props.building.location_number}
|
||||
pattern={locationNumberPattern}
|
||||
mode={props.mode}
|
||||
copy={props.copy}
|
||||
onChange={props.onChange}
|
||||
step={1}
|
||||
min={1}
|
||||
tooltip={dataFields.location_number.tooltip}
|
||||
/>
|
||||
<Verification
|
||||
slug="location_number"
|
||||
|
@ -57,7 +57,8 @@ export const dataFields = { /* eslint-disable @typescript-eslint/camelcase */
|
||||
location_number: {
|
||||
category: Category.Location,
|
||||
title: "Building number",
|
||||
example: 12,
|
||||
example: '12b',
|
||||
tooltip: 'Numbers with an optional lowercase letter are accepted, e.g. 141 or 12b'
|
||||
},
|
||||
location_street: {
|
||||
category: Category.Location,
|
||||
|
Loading…
Reference in New Issue
Block a user