Skip to content

Commit

Permalink
Add unselected option to select widget when no default is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Benaiah committed Oct 10, 2017
1 parent 046711a commit 337d876
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/components/Widgets/SelectControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ export default class SelectControl extends React.Component {
return <div>Error rendering select control for {field.get('name')}: No options</div>;
}

const options = fieldOptions.map((option) => {
if (typeof option === 'string') {
return { label: option, value: option };
}
return option;
});
const options = [
...(field.get('default', false) ? [] : [{ label: '<not set>', value: '' }]),
...fieldOptions.map((option) => {
if (typeof option === 'string') {
return { label: option, value: option };
}
return option;
}),
];

return (<select id={forID} value={value || ''} onChange={this.handleChange}>
{options.map((option, idx) => <option key={idx} value={option.value}>
Expand Down

0 comments on commit 337d876

Please sign in to comment.