diff --git a/apps/src/templates/SchoolAutocompleteDropdown.jsx b/apps/src/templates/SchoolAutocompleteDropdown.jsx
index 919e90aabf4d9..25f70569d2877 100644
--- a/apps/src/templates/SchoolAutocompleteDropdown.jsx
+++ b/apps/src/templates/SchoolAutocompleteDropdown.jsx
@@ -11,16 +11,21 @@ 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,
+ schoolFilter: PropTypes.func,
};
static defaultProps = {
- fieldName: "nces_school_s"
+ fieldName: "nces_school_s",
+ schoolFilter: () => true,
};
+
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 = () => ({
@@ -45,7 +50,7 @@ export default class SchoolAutocompleteDropdown extends Component {
fetch(searchUrl)
.then(response => response.ok ? response.json() : [])
.then(json => {
- const schools = json.map(school => this.constructSchoolOption(school));
+ const schools = json.filter(this.props.schoolFilter).map(school => this.constructSchoolOption(school));
schools.unshift(this.constructSchoolNotFoundOption());
return { options: schools };
})
@@ -93,7 +98,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..ee5c639c722bb 100644
--- a/apps/src/templates/census2017/SchoolAutocompleteDropdownWithLabel.jsx
+++ b/apps/src/templates/census2017/SchoolAutocompleteDropdownWithLabel.jsx
@@ -30,8 +30,12 @@ export default class SchoolAutocompleteDropdownWithLabel extends Component {
fieldName: PropTypes.string,
singleLineLayout: PropTypes.bool,
showRequiredIndicator: PropTypes.bool,
+ schoolDropdownOption: PropTypes.object,
+ schoolFilter: PropTypes.func,
};
+ schoolDropdown = undefined;
+
static defaultProps = {
showRequiredIndicator: true,
};
@@ -43,12 +47,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 +79,12 @@ export default class SchoolAutocompleteDropdownWithLabel extends Component {
{!singleLineLayout && showError && errorDiv}