RamAlx
RamAlx

Reputation: 7334

Setting a value in an input Field in Redux Form

i want to create a field using redux form which will contains a "readOnly" box which will have a default value.

So im writing

<Field id="current-password" 
       name="current-password" 
       type="text"
       readOnly="readOnly"
       component={inputField}>
       value={userNumber}     
</Field>

The userNumber is a prop. The inputField is: i

mport React from 'react';
import { Input } from 'reactstrap';


export default field => (
  <div>
    <Input {...field.input} type={field.type}>
      {field.children}
    </Input>
    {field.meta.touched && field.meta.error &&
    <span className="error">{field.meta.error}</span>}
  </div>
);

My layout is like this: enter image description here

When my component is render i want it to appear like this. The problem is that the "value" prop is not assigned. How to solve this?

Upvotes: 2

Views: 1360

Answers (1)

Kevin Ortman
Kevin Ortman

Reputation: 1919

Consider mapping state to the initialValues prop in your form declaration.

Here's how I did it:

function mapStateToProps(state) {
    return {
        request: state.request,
        initialValues: state.auth,
    };
}

A fully documented example is here Initialize From State

Upvotes: 2

Related Questions