2

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?

1
  • Anyone to know how to figure it out?? Commented Feb 15, 2017 at 15:16

1 Answer 1

2

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

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.