Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot pass formatter to Input #44

Open
sklinov opened this issue Jul 1, 2020 · 4 comments
Open

Cannot pass formatter to Input #44

sklinov opened this issue Jul 1, 2020 · 4 comments

Comments

@sklinov
Copy link

sklinov commented Jul 1, 2020

I would like to use formatter and parser function to <Input> or <InputNumber /> components, but can't figure out how to pass those functions.
I've tried adding them to widgetProps, or getValueProps but that didn't seem to work.
Thanks!

@supnate
Copy link
Contributor

supnate commented Jul 2, 2020

For InputNumber you should be able to pass formatter or parser to the component by widgetProps. I don't see them as the API of Input from antd's docs.

@sklinov
Copy link
Author

sklinov commented Jul 2, 2020

Thanks for prompt answer.
Yeah, you're right, there's no formatter or parser for regular Input.
I should probably try to use getValueFromEvent and pass it using fieldProps

@supnate
Copy link
Contributor

supnate commented Jul 2, 2020

You can wrap Input to a new custom component with formatter supported. Like:

const MyInput = props => {
  const { value, onChange, formatter, parser } = props;
  const newValue = formatter(value);
  const newOnChange = value => onChange(parser(value));
  const newProps = _.omit(props, ['value', 'onChange', 'formatter', 'parser']);
  return <Input {...newProps} value={newValue} onChange={newOnChange} />
}

@sklinov
Copy link
Author

sklinov commented Jul 2, 2020

Great, thanks for the support! I'll give it a try

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

No branches or pull requests

2 participants