-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
Approach Suggestion Request #97
Labels
Type: Question
Questions and other discussions
Comments
Here's my new workaround, a HOC to handle that /**
* A wrapper for AutoForm which stores the formRef in state and
* passes back into the form
*/
export default function HOCformable(Component) {
const klass = class extends React.Component {
constructor(props) {
super(props);
this.state = { formRef: null };
this.setFormRef = this.handleFormRef.bind(this);
}
handleFormRef(formRef) {
if (formRef && !this.state.formRef) {
this.setState({ formRef });
}
}
render() {
return <Component
{...this.props}
formRef={this.state.formRef}
setFormRef={this.setFormRef}
/>;
}
};
klass.displayName = `Formable(${Component.name})`;
return klass;
} |
Before I answer... Why you have to pass your form ref down? |
Because I may have a sub-Component do the |
Okay, that makes sense. Currently, I don't have a better idea than some variation of your HOC, but if I do - I'll post it here. |
sounds good - thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been working with the awesome
onSubmitSuccess()
and returned promise fromformRef.submit()
which was introduced after #51 --- excellent.But I have run into issues where I want to create a form and pass the formRef into it's child elements... for example, a submit button child component.
The issue is the
formRef
isnull
, it gets set when AutoForm creates it, but it doesn't get passed into the child elements because they are not yet instantiated...null
gets passed.example:
I suppose I could set
formRef
into the parent component state, which would trigger an update, and set it to child components explicitly...Is there a simpler strategy?
What I'd like is, maybe, a function imported from the
uniforms
package which basically could find and return theformRef
, from anything inside the form... I have no idea how this could be accomplished, and probably can't... The submit button is obviously not an input, it is not initiated with aconnectField
but I suppose we could have aconnectComponent
to tie "whatever" to theformRef
, and thereby, with API access to the form.Thoughts?
The text was updated successfully, but these errors were encountered: