ducky/web
5:efdc78cbdac5 Browse Files
Update our ValidationError component to accept arrays. Allow our ValidationError component to match an array of fields, headers, or params. This is for components that may address multiple inputs (e.g., month/year inputs) but also lays the ground work for inverse-matching. Ideally, inverse-matching and matching ValidationErrors should mirror each other, logically, so the syntax is identical. But we also should have the common use case easily supported, so if you use field instead of fields (or header/headers, param/params) we'll automatically turn that into an array.
src/components/validation-error.jsx
1.1 --- a/src/components/validation-error.jsx Sun May 31 16:38:32 2015 -0400 1.2 +++ b/src/components/validation-error.jsx Sun May 31 17:20:32 2015 -0400 1.3 @@ -4,9 +4,18 @@ 1.4 displayName: 'ValidationError', 1.5 1.6 render () { 1.7 - const field = this.props.field 1.8 - const param = this.props.param 1.9 - const header = this.props.header 1.10 + let fields = this.props.fields 1.11 + if (this.props.field && !this.props.fields) { 1.12 + fields = [this.props.field] 1.13 + } 1.14 + let params = this.props.params 1.15 + if (this.props.param && !this.props.params) { 1.16 + params = [this.props.param] 1.17 + } 1.18 + let headers = this.props.headers 1.19 + if (this.props.header && !this.props.headers) { 1.20 + headers = [this.props.header] 1.21 + } 1.22 const outputs = this.props.outputs 1.23 const errors = this.props.errors 1.24 return ( 1.25 @@ -16,13 +25,13 @@ 1.26 if (!error.field && !error.param && !error.header) { 1.27 return '' 1.28 } 1.29 - if (field && error.field && error.field != field) { 1.30 + if (fields && error.field && fields.indexOf(error.field) < 0) { 1.31 return '' 1.32 } 1.33 - if (param && error.param && error.param != param) { 1.34 + if (params && error.param && params.indexOf(error.param) < 0) { 1.35 return '' 1.36 } 1.37 - if (header && error.header && error.header != header) { 1.38 + if (headers && error.header && headers.indexOf(error.header) < 0) { 1.39 return '' 1.40 } 1.41 if (outputs[error.error] == undefined) {