From 3c02aaa9c768ae6471bcfdcf58f61a44f995b929 Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Mon, 27 Feb 2017 10:08:28 -0500 Subject: [PATCH] Updated search bar to validate the length and type of input of BBL, Building ID and Lot ID --- src/containers/SearchBar/index.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/containers/SearchBar/index.js b/src/containers/SearchBar/index.js index 366fa6c4..7883cfd3 100644 --- a/src/containers/SearchBar/index.js +++ b/src/containers/SearchBar/index.js @@ -35,7 +35,9 @@ class BuildingList extends Component { onFormSubmit = (event) => { event.preventDefault(); - this.getBuildings(); + if (!(this.checkTermLength() || this.checkTermType())) { + this.getBuildings(); + } } getBuildings = () => { @@ -58,6 +60,29 @@ class BuildingList extends Component { return actual; } + checkTermLength = () => { + if (this.state.type === 'bbl') return this.state.term.length > 20; + else if (this.state.type === 'building id') return this.state.term.length > 10; + else if (this.state.type === 'lot id') return this.state.term.length > 10; + return false; + } + + checkTermType = () => isNaN(this.state.term); + + showWarning = () => { + let warning = null; + if (this.checkTermLength()) warning = 'is too long'; + if (this.checkTermType()) warning = 'can only have numbers'; + if (this.checkTermLength() || this.checkTermType()) { + return ( +
+ {this.state.type} {warning} +
+ ); + } + return
; + } + generateTypeList = () => { const html = SEARCH_TYPE_LIST.map((val) => { /* TODO: Remove tag and make it a