1

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?

3
  • have you tried defining the valueField and textField of Multiselect? jquense.github.io/react-widgets/docs/#/multiselect/… Commented Dec 6, 2016 at 15:58
  • @Adam Did you ever find a solution to this? I am running into the same problem, everything looks how the docs say Commented Feb 6, 2017 at 19:25
  • 2
    @John In the end I couldn't, so before submitting the form to the API I altered it like target_city_ids: request.target_city_ids.map(city => city.id). Sorry I couldn't be more help! Commented Feb 7, 2017 at 19:15

1 Answer 1

1

try to use valueField:

<Multiselect
    valueField="id"
/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.