diff --git a/src/containers/SearchBar/index.js b/src/containers/SearchBar/index.js index 366fa6c475957021b15ec83b6c132a3233c34d77..7883cfd363819ef5df4875e0d758c9082abe7dd3 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