Skip to content

Instantly share code, notes, and snippets.

@JulienMelissas
Forked from keeth/Select.js
Last active September 12, 2017 22:44
Show Gist options
  • Select an option

  • Save JulienMelissas/f383d64243acba7c675935180ccc29f0 to your computer and use it in GitHub Desktop.

Select an option

Save JulienMelissas/f383d64243acba7c675935180ccc29f0 to your computer and use it in GitHub Desktop.
A formsy-react wrapper around React Select (ES6)
import React from 'react';
import Formsy from 'formsy-react';
import ReactSelect from 'react-select';
import './Select.less';
const Select = React.createClass({
mixins: [Formsy.Mixin],
propTypes: {
id: React.PropTypes.string.isRequired,
title: React.PropTypes.string.isRequired,
name: React.PropTypes.string.isRequired,
multiple: React.PropTypes.bool,
options: React.PropTypes.array.isRequired
},
changeValue(value, selectedOptions) {
this.setValue(selectedOptions);
},
render() {
var className = this.showRequired() ? 'required' : this.showError() ? 'error' : null;
var errorMessage = this.getErrorMessage();
return (
<div className={'form-group' + (className ? ' ' + className : '') }>
<label htmlFor={this.props.id}>{this.props.title}</label>
<ReactSelect
ref="select"
id={this.props.id}
name={this.props.name}
multi={this.props.multiple}
onChange={this.changeValue}
value={this.getValue()}
options={this.props.options}
/>
<span className='error-message'>{errorMessage}</span>
</div>
);
}
});
export default Select;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment