davidkpiano / react-redux-form

Create forms easily in React with Redux.
https://davidkpiano.github.io/react-redux-form
MIT License
2.06k stars 252 forks source link

set array from input value #1143

Open bodokaiser opened 6 years ago

bodokaiser commented 6 years ago

The Problem

I am not able to set up a custom control which converts a comma separated floats from string to array.

Steps to Reproduce

See codepen link at the bottom for complete example and type "1,2,3" into the input.

<Control.text model="data" mapProps={{
  onBlur: ({ model, dispatch }) => {
    return event => {
      var value = event.target.value.split(',').map(s => parseFloat(s.trim()))

      console.log('blur', value)
      dispatch(actions.change(model, value))
      dispatch(actions.setTouched(model))
    }
  }
}} />

Expected Behavior

On submit my model should be { data: [1,2,3] }.

Actual Behavior

Model is {}.

Reproducible Code Example

https://codepen.io/anon/pen/mLMpwe?editors=0010#0

Ogek commented 6 years ago

You must have "model" property on LocalForm and the property path as "model" property of its fields.

Example:

<LocalForm model="person">
<Control.text model="person.name"/>
<Control.text model="person.surname"/>
</LocalForm>