From 1956b572e1c5af50e6ddf284baf682d8eeacfdc1 Mon Sep 17 00:00:00 2001 From: Drew Samnick Date: Wed, 14 Feb 2018 16:47:07 -0800 Subject: [PATCH 1/4] Allow school dropdown to send full object and to accept an option --- apps/src/templates/SchoolAutocompleteDropdown.jsx | 9 ++++++--- .../SchoolAutocompleteDropdownWithLabel.jsx | 13 +++++++++++-- dashboard/lib/api/v1/school_autocomplete.rb | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/src/templates/SchoolAutocompleteDropdown.jsx b/apps/src/templates/SchoolAutocompleteDropdown.jsx index 919e90aabf4d9..9e3bc8cb26274 100644 --- a/apps/src/templates/SchoolAutocompleteDropdown.jsx +++ b/apps/src/templates/SchoolAutocompleteDropdown.jsx @@ -11,16 +11,19 @@ export default class SchoolAutocompleteDropdown extends Component { onChange: PropTypes.func.isRequired, // Value is the NCES id of the school value: PropTypes.string, - fieldName: PropTypes.string + fieldName: PropTypes.string, + schoolDropdownOption: PropTypes.object, }; static defaultProps = { fieldName: "nces_school_s" }; + constructSchoolOption = school => ({ value: school.nces_id.toString(), - label: `${school.name} - ${school.city}, ${school.state} ${school.zip}` + label: `${school.name} - ${school.city}, ${school.state} ${school.zip}`, + school: school, }); constructSchoolNotFoundOption = () => ({ @@ -93,7 +96,7 @@ export default class SchoolAutocompleteDropdown extends Component { loadOptions={this.getOptions} cache={false} filterOption={() => true} - value={this.props.value} + value={this.props.schoolDropdownOption ? this.props.schoolDropdownOption : this.props.value} onChange={this.props.onChange} placeholder={i18n.searchForSchool()} /> diff --git a/apps/src/templates/census2017/SchoolAutocompleteDropdownWithLabel.jsx b/apps/src/templates/census2017/SchoolAutocompleteDropdownWithLabel.jsx index 0c09a444ef709..f722eeb27814e 100644 --- a/apps/src/templates/census2017/SchoolAutocompleteDropdownWithLabel.jsx +++ b/apps/src/templates/census2017/SchoolAutocompleteDropdownWithLabel.jsx @@ -30,8 +30,11 @@ export default class SchoolAutocompleteDropdownWithLabel extends Component { fieldName: PropTypes.string, singleLineLayout: PropTypes.bool, showRequiredIndicator: PropTypes.bool, + schoolDropdownOption: PropTypes.object, }; + schoolDropdown = undefined; + static defaultProps = { showRequiredIndicator: true, }; @@ -43,12 +46,16 @@ export default class SchoolAutocompleteDropdownWithLabel extends Component { handleSchoolNotFoundCheckbox(event) { var checkbox = event.target; if (checkbox.checked) { - this.props.setField("nces", {value: "-1"}); + this.props.setField("nces", this.schoolDropdown.constructSchoolNotFoundOption()); } else { - this.props.setField("nces", {value: ""}); + this.props.setField("nces", this.props.schoolDropdownOption); } } + bindDropdown = (dropdown) => { + this.schoolDropdown=dropdown; + }; + render() { const {showRequiredIndicator, singleLineLayout} = this.props; const questionStyle = {...styles.question, ...(singleLineLayout && singleLineLayoutStyles)}; @@ -71,9 +78,11 @@ export default class SchoolAutocompleteDropdownWithLabel extends Component { {!singleLineLayout && showError && errorDiv}