Benison
Benison

Reputation: 167

defaultValue is not filled in textarea when used with react-final-form

I unable set the defaultValue to the text area, I am using react-final-form and wrapped the TextareaField inside the Field element of react-final-form

Here is my code:

class App extends React.Component {
  submitForm(values) {
   .....
  }

 renderForm({ handleSubmit }) {
  return (
   <form
    onSubmit={handleSubmit}
   >
    <Field
      name="description"
    >
      {({ input, meta }) => (
        <TextareaField
          label='Description'
          error={meta.error}
          isInvalid={meta.submitFailed && !meta.valid}
          inputAttrs={{
            placeholder: 'Desc..',
          }}
          defaultValue='my text'
          onChange={(e) => { input.onChange(e.target.value); }}
          value={input.value}
          required
        />
      )}
    </Field>
    <Button text="Submit" type={Button.Opts.Types.SUBMIT} />
  </form>
 );
}
render() {
  return (
    <Form
      onSubmit={this.submitForm}
      render={this.renderForm}
      validate={(values) => {
        const errors = {};
        if (!values.description) {
          errors.description = 'Required';
        }
        return errors;
      }}
    />
   );
 }
}

Terribly stuck, where am I missing??

Upvotes: 1

Views: 1814

Answers (1)

Erik R.
Erik R.

Reputation: 7272

If you want my text to be the initial value in your field, you'll need to pass initialValues={{ description: 'my text' }} to the Form component.

Upvotes: 3

Related Questions