I am using redux-form and react-widgets. My form has a multiselect field. My field in the form looks like this:
<Field
valueField="id"
textField="label"
label="Target Cities"
name="target_city_ids"
component={MultiSelectField}
data={cities.map(city => {'id': city.id, 'label': city.name })}/>
My MultiSelectField looks like this:
import React, { Component, PropTypes } from 'react';
import classNames from 'classnames'
import { Multiselect } from 'react-widgets'
const MultiSelectField = (field) => {
let { input, label, meta: { error }, ...rest } = field
let fieldClass = classNames({
'form-group': true,
'has-error': error
})
return (
<div className={fieldClass}>
<label className="control-label">{label}</label>
<Multiselect
className="rw-form-control"
filter="contains"
{...input}
onBlur={() => input.onBlur()}
value={input.value || []} // requires value to be an array
{...rest}/>
{error && <span className="help-block">{error}</span>}
</div>
)
}
At the moment, when I pick an option in the multiselect it saves the value for the field as an object:
{id:'x', label:'y'}
How can I make only the id be saved as the value, and not the whole object?
target_city_ids: request.target_city_ids.map(city => city.id). Sorry I couldn't be more help!