react-redux-form icon indicating copy to clipboard operation
react-redux-form copied to clipboard

set array from input value

Open bodokaiser opened this issue 6 years ago • 1 comments

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

bodokaiser avatar May 04 '18 10:05 bodokaiser

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>

Ogek avatar May 08 '18 13:05 Ogek