Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Correct use with mapPropsToFields and getFieldDecorator? #1

Closed
JeffJankowski opened this issue May 19, 2019 · 7 comments
Closed

Correct use with mapPropsToFields and getFieldDecorator? #1

JeffJankowski opened this issue May 19, 2019 · 7 comments

Comments

@JeffJankowski
Copy link

  • I'm submitting a ...
    [ ] bug report
    [x] feature request
    [ ] question about the decisions made in the repository
    [x] question about how to use this project

  • Summary

Is is possible to use this component with Form.getFieldDecorator()? As a drop-in replacement to <Input />, the value is getting overwritten with the following warning in the console:

Warning: getFieldDecorator will override value, so please don't set value directly and use setFieldsValue to set it.

@antoniopresto
Copy link
Owner

Thank you for reporting. I have not yet used with getFieldDecorator;
Is it just a warning or does it not work?

@JeffJankowski
Copy link
Author

It did not work at all, unfortunately. I'm now using react-text-mask and rendering the antd Input as a custom component, which is working sufficiently.

@astrikov-d
Copy link

astrikov-d commented Jun 14, 2019

@JeffJankowski, I'm experiencing same issue with antd. Can you please show me an example how you've solved this with react-text-mask? Thank you.

Update:
My solution is:

<MaskedInput autoComplete={'off'}
                         mask={[/\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, ' ', /\d/, /\d/]}
                         render={(ref, props) => (
                                 <input className={'ant-input'} ref={(input) => ref(input)} {...props} />
                         )}/>

@JeffJankowski
Copy link
Author

@astrikov-d, I learned on a random thread that I needed to grab the inner input element for the reference to bind correctly.

<MaskedInput
  render={(ref, passedProps: Props) => (
    <Input
      value={value}
      ref={input => input && ref(input.input)}
      {...passedProps}
    />
  )}
/>;

@maksaimer
Copy link

I have the same problem with getFieldDecorator

@JeffJankowski
Copy link
Author

@maksaimer Before switching to Formik, I got getFieldDecorator to work with react-text-mask by doing something like:

<MaskedInput
  {...props}
  render={(ref, passedProps: Props) => {
    const { field, formUtils, ...otherProps } = passedProps;
    // this is kept in sync with value, and will produce warnings with getFieldDecorator()
    // if the prop is not deleted
    delete otherProps.defaultValue;
    return formUtils.getFieldDecorator(field)(
      <Input ref={input => input && ref(input.input)} {...otherProps} />
    );
  }}
/>

@antoniopresto
Copy link
Owner

Sorry for the delay, can you test version 0.1.7. please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants