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

Call wrapped form's methods from outside #9

Closed
artkravchenko opened this issue May 15, 2016 · 5 comments

Comments

@artkravchenko
Copy link
Contributor

@artkravchenko artkravchenko commented May 15, 2016

Hello,
Do I have any way to call wrapped form's methods? The wrapper has fields and errors properties but it looks like I don't have real access to the wrapped form.

In addition, it can be awesome to add an opportunity to force validate the form remotely.

@theadam

This comment has been minimized.

Copy link
Owner

@theadam theadam commented May 19, 2016

Are you attempting to use refs to get access to the form? Is this what you mean by from the outside?

@artkravchenko

This comment has been minimized.

Copy link
Contributor Author

@artkravchenko artkravchenko commented May 22, 2016

@theadam Yes, I try to manage the form with refs. For example, I have

<WrappedForm ref={c => this.form = c} />

And then I call this.form.method().

@theadam

This comment has been minimized.

Copy link
Owner

@theadam theadam commented May 26, 2016

I am not sure I want to put too much effort into an API to be used with a reference to a form at the moment. However, if you are using the latest version, you should be able to either use this.form.formProps().forceValidate() or this.form.touch(fieldNameArray). The second will force every field name in the array to start passing errors down. Let me know if this works.

@artkravchenko

This comment has been minimized.

Copy link
Contributor Author

@artkravchenko artkravchenko commented Jun 1, 2016

Thank you, @theadam! I have tried the first way (this.form.formProps()), so it works and returns forms utility functions (https://github.com/theadam/react-inform#form). I think you should add a tip to docs that if user needs to get access to that functions (from outside), he has to call this.form.formProps(). There's no information about it anywhere :)

@theadam

This comment has been minimized.

Copy link
Owner

@theadam theadam commented Jun 1, 2016

Good @Oopscurity. Id like to think of a different way to provide this functionality from the outside. I personally try to avoid refs as much as possible, as it breaks the declarative nature of the view. My instinct would be to allow that property to be controlled with passed props, but it feels clunky to me. If I do not think of another approach, I might end up documenting this. Just beware, the api might change in future versions! Glad it worked!

@theadam theadam closed this Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.