fix: add empty options to dropdowns (#246)

ARCH-1165: Add an empty option so that users can delete values they set for education, spoken language, and country of origin
This commit is contained in:
Adam Butterworth
2019-09-11 12:54:17 -04:00
committed by GitHub
parent 2b280f12fc
commit 6dd2a0c78e
3 changed files with 9 additions and 8 deletions

View File

@@ -83,6 +83,7 @@ class Country extends React.Component {
value={country}
onChange={this.handleChange}
>
<option value="" />
{sortedCountries.map(({ code, name }) => (
<option key={code} value={code}>{name}</option>
))}

View File

@@ -78,6 +78,7 @@ class Education extends React.Component {
value={levelOfEducation}
onChange={this.handleChange}
>
<option value="" />
{EDUCATION_LEVELS.map(level => (
<option key={level} value={level}>
{intl.formatMessage(get(

View File

@@ -26,19 +26,17 @@ class PreferredLanguage extends React.Component {
}
handleChange(e) {
const {
name,
value: rawValue,
} = e.target;
let value = rawValue;
const { name, value } = e.target;
// Restructure the data.
// We deconstruct our value prop in render() so this
// changes our data's shape back to match what came in
if (name === this.props.formId) {
value = [{ code: rawValue }];
if (value !== '') {
this.props.changeHandler(name, [{ code: value }]);
} else {
this.props.changeHandler(name, []);
}
}
this.props.changeHandler(name, value);
}
handleSubmit(e) {
@@ -92,6 +90,7 @@ class PreferredLanguage extends React.Component {
value={value}
onChange={this.handleChange}
>
<option value="" />
{sortedLanguages.map(({ code, name }) => (
<option key={code} value={code}>{name}</option>
))}