Last active
March 19, 2020 03:30
-
-
Save osmanyz/0a76916abe4a74defdb80581c051aadb to your computer and use it in GitHub Desktop.
This's package just for `redux-form` multiple-select. That's style for evergreen-ui package. That's working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyForm { | |
| onSubmit(values) { | |
| values.types = JSON.stringify(values.types); | |
| // ... your formAction method is here. | |
| } | |
| render { | |
| return ( | |
| <React.Fragment> | |
| <form onSubmit={this.props.handleSubmit(this.onSubmit.bind(this))} method="post"> | |
| <Field | |
| type="select-multiple" | |
| name="types" | |
| isRequired={true} | |
| selectedOptions={this.props.selectedTypes} | |
| renderOptions={this.props.myTypes.map(item => ( | |
| <option key={item.id} value={item.id}>{item.name}</option> | |
| ))} | |
| label={lang('Type Control')} | |
| component={renderSelectMultiField} | |
| /> | |
| </form> | |
| </React.Fragment> | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class renderSelectMultiField extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| let selectedOptions = []; | |
| if (this.props.selectedOptions) { | |
| this.props.selectedOptions.map(item => (selectedOptions.push(item.id))); | |
| } | |
| this.state = { | |
| selected: selectedOptions || [], | |
| }; | |
| this.handleOnChange = this.handleOnChange.bind(this); | |
| } | |
| handleOnChange (e) { | |
| let value = Array.from(e.target.selectedOptions, option => option.value); | |
| if (value) { | |
| this.setState({ | |
| selected: value, | |
| }); | |
| if (changeFieldValue) { | |
| changeFieldValue(this.props.input.name, value); | |
| } | |
| } | |
| } | |
| render() { | |
| return ( | |
| <Pane marginBottom={20}> | |
| <Label | |
| htmlFor={this.props.input.id} | |
| marginBottom={4} | |
| display="block"> | |
| {requiredLabel(this.props)} | |
| </Label> | |
| <select | |
| className="css-5ljhhe 📦color_425A70 📦fnt-fam_b77syt 📦fnt-sze_12px 📦f-wght_400 📦ln-ht_16px 📦ltr-spc_0 📦w_100prcnt 📦pl_10px 📦pr_10px 📦bblr_3px 📦bbrr_3px 📦btlr_3px 📦btrr_3px 📦box-szg_border-box" | |
| style={{height: 140, lineHeight: 20}} | |
| multiple={true} | |
| {...this.props.input} | |
| value={this.state.selected} | |
| onChange={this.handleOnChange}> | |
| {this.props.options && this.props.options.map(type => { | |
| return (<option key={type.name} value={type.name}>{type.label}</option>); | |
| })} | |
| {this.props.renderOptions && this.props.renderOptions} | |
| </select> | |
| {(this.props.meta.touched && this.props.meta.error) && ( | |
| <Text fontSize={12} color="red"> | |
| <Icon icon="error" color="danger" marginRight={7} marginTop={10}/> | |
| {this.props.meta.error} | |
| </Text> | |
| )} | |
| </Pane> | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment