How to trigger submit from parent?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I would like to call the submit method of the child component. Therefore I use the ref prop.
But it looks like I just get a WithContext object.



So how to call TodoForm > submit inside App > submitForm.



Here is a running example: https://codesandbox.io/s/92nm15pnqr










share|improve this question























  • from App.js pass onSubmit={this.submitForm} and from TodoForm in Formik onSubmit add this.props.onSubmit()

    – Rutvik Bhatt
    Nov 16 '18 at 12:02













  • The submit button is outside of the TodoForm. Thus, submit should be triggered outside of the TodoForm.Therefore onSubmit prop for TodoForm will not help.

    – user3481997
    Nov 16 '18 at 12:09











  • why do you put submit button outside?

    – Rutvik Bhatt
    Nov 16 '18 at 12:13











  • For example bootstrap modal where submit button is in the modal footer and the form itself is in the modal body.

    – user3481997
    Nov 16 '18 at 12:55


















1















I would like to call the submit method of the child component. Therefore I use the ref prop.
But it looks like I just get a WithContext object.



So how to call TodoForm > submit inside App > submitForm.



Here is a running example: https://codesandbox.io/s/92nm15pnqr










share|improve this question























  • from App.js pass onSubmit={this.submitForm} and from TodoForm in Formik onSubmit add this.props.onSubmit()

    – Rutvik Bhatt
    Nov 16 '18 at 12:02













  • The submit button is outside of the TodoForm. Thus, submit should be triggered outside of the TodoForm.Therefore onSubmit prop for TodoForm will not help.

    – user3481997
    Nov 16 '18 at 12:09











  • why do you put submit button outside?

    – Rutvik Bhatt
    Nov 16 '18 at 12:13











  • For example bootstrap modal where submit button is in the modal footer and the form itself is in the modal body.

    – user3481997
    Nov 16 '18 at 12:55














1












1








1








I would like to call the submit method of the child component. Therefore I use the ref prop.
But it looks like I just get a WithContext object.



So how to call TodoForm > submit inside App > submitForm.



Here is a running example: https://codesandbox.io/s/92nm15pnqr










share|improve this question














I would like to call the submit method of the child component. Therefore I use the ref prop.
But it looks like I just get a WithContext object.



So how to call TodoForm > submit inside App > submitForm.



Here is a running example: https://codesandbox.io/s/92nm15pnqr







reactjs formik






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 11:45









user3481997user3481997

2611313




2611313













  • from App.js pass onSubmit={this.submitForm} and from TodoForm in Formik onSubmit add this.props.onSubmit()

    – Rutvik Bhatt
    Nov 16 '18 at 12:02













  • The submit button is outside of the TodoForm. Thus, submit should be triggered outside of the TodoForm.Therefore onSubmit prop for TodoForm will not help.

    – user3481997
    Nov 16 '18 at 12:09











  • why do you put submit button outside?

    – Rutvik Bhatt
    Nov 16 '18 at 12:13











  • For example bootstrap modal where submit button is in the modal footer and the form itself is in the modal body.

    – user3481997
    Nov 16 '18 at 12:55



















  • from App.js pass onSubmit={this.submitForm} and from TodoForm in Formik onSubmit add this.props.onSubmit()

    – Rutvik Bhatt
    Nov 16 '18 at 12:02













  • The submit button is outside of the TodoForm. Thus, submit should be triggered outside of the TodoForm.Therefore onSubmit prop for TodoForm will not help.

    – user3481997
    Nov 16 '18 at 12:09











  • why do you put submit button outside?

    – Rutvik Bhatt
    Nov 16 '18 at 12:13











  • For example bootstrap modal where submit button is in the modal footer and the form itself is in the modal body.

    – user3481997
    Nov 16 '18 at 12:55

















from App.js pass onSubmit={this.submitForm} and from TodoForm in Formik onSubmit add this.props.onSubmit()

– Rutvik Bhatt
Nov 16 '18 at 12:02







from App.js pass onSubmit={this.submitForm} and from TodoForm in Formik onSubmit add this.props.onSubmit()

– Rutvik Bhatt
Nov 16 '18 at 12:02















The submit button is outside of the TodoForm. Thus, submit should be triggered outside of the TodoForm.Therefore onSubmit prop for TodoForm will not help.

– user3481997
Nov 16 '18 at 12:09





The submit button is outside of the TodoForm. Thus, submit should be triggered outside of the TodoForm.Therefore onSubmit prop for TodoForm will not help.

– user3481997
Nov 16 '18 at 12:09













why do you put submit button outside?

– Rutvik Bhatt
Nov 16 '18 at 12:13





why do you put submit button outside?

– Rutvik Bhatt
Nov 16 '18 at 12:13













For example bootstrap modal where submit button is in the modal footer and the form itself is in the modal body.

– user3481997
Nov 16 '18 at 12:55





For example bootstrap modal where submit button is in the modal footer and the form itself is in the modal body.

– user3481997
Nov 16 '18 at 12:55












1 Answer
1






active

oldest

votes


















0














Because you wrap your TodoForm component in withNamespaces HOC, getting the reference to your TodoForm is not as easy as calling ref={..}, since that returns reference to the HOC. To get the reference to your component, you have to leverage the innerRef parameter, when creating the HOC (see docs)



const TodoFormTranslated = withNamespaces("", {
innerRef: (ref) => VARIABLE_WHICH_WILL_NOW_CONTAIN_REF_TO_YOUR_EL = ref
})(TodoForm);


fast but working solution to your problem would look something like this: https://codesandbox.io/s/n55yvw1o2m



Maybe you don't want variables outside of your class, so I'll leave that to you in which way do you want to handle this. You can get inspiration for example from this post.






share|improve this answer
























  • have this helped solving your issue?

    – Matej P.
    Nov 16 '18 at 16:06











  • Unfortunately not. I was able to access the method in child component but I had no access to formik specific props like submitForm. So I decided to solve this issue with an additional props in TodoForm to trigger the form submit. This has the disadvantage that I need to write additional code but I see no other way.

    – user3481997
    Nov 16 '18 at 18:30











  • but you were able to run the submit method of the TodoForm then right? that what the question stated. You can post another question for the next issue.

    – Matej P.
    Nov 16 '18 at 21:59













  • OK, from that perspective the problem is solved. :-)

    – user3481997
    Nov 19 '18 at 6:51












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337227%2fhow-to-trigger-submit-from-parent%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Because you wrap your TodoForm component in withNamespaces HOC, getting the reference to your TodoForm is not as easy as calling ref={..}, since that returns reference to the HOC. To get the reference to your component, you have to leverage the innerRef parameter, when creating the HOC (see docs)



const TodoFormTranslated = withNamespaces("", {
innerRef: (ref) => VARIABLE_WHICH_WILL_NOW_CONTAIN_REF_TO_YOUR_EL = ref
})(TodoForm);


fast but working solution to your problem would look something like this: https://codesandbox.io/s/n55yvw1o2m



Maybe you don't want variables outside of your class, so I'll leave that to you in which way do you want to handle this. You can get inspiration for example from this post.






share|improve this answer
























  • have this helped solving your issue?

    – Matej P.
    Nov 16 '18 at 16:06











  • Unfortunately not. I was able to access the method in child component but I had no access to formik specific props like submitForm. So I decided to solve this issue with an additional props in TodoForm to trigger the form submit. This has the disadvantage that I need to write additional code but I see no other way.

    – user3481997
    Nov 16 '18 at 18:30











  • but you were able to run the submit method of the TodoForm then right? that what the question stated. You can post another question for the next issue.

    – Matej P.
    Nov 16 '18 at 21:59













  • OK, from that perspective the problem is solved. :-)

    – user3481997
    Nov 19 '18 at 6:51
















0














Because you wrap your TodoForm component in withNamespaces HOC, getting the reference to your TodoForm is not as easy as calling ref={..}, since that returns reference to the HOC. To get the reference to your component, you have to leverage the innerRef parameter, when creating the HOC (see docs)



const TodoFormTranslated = withNamespaces("", {
innerRef: (ref) => VARIABLE_WHICH_WILL_NOW_CONTAIN_REF_TO_YOUR_EL = ref
})(TodoForm);


fast but working solution to your problem would look something like this: https://codesandbox.io/s/n55yvw1o2m



Maybe you don't want variables outside of your class, so I'll leave that to you in which way do you want to handle this. You can get inspiration for example from this post.






share|improve this answer
























  • have this helped solving your issue?

    – Matej P.
    Nov 16 '18 at 16:06











  • Unfortunately not. I was able to access the method in child component but I had no access to formik specific props like submitForm. So I decided to solve this issue with an additional props in TodoForm to trigger the form submit. This has the disadvantage that I need to write additional code but I see no other way.

    – user3481997
    Nov 16 '18 at 18:30











  • but you were able to run the submit method of the TodoForm then right? that what the question stated. You can post another question for the next issue.

    – Matej P.
    Nov 16 '18 at 21:59













  • OK, from that perspective the problem is solved. :-)

    – user3481997
    Nov 19 '18 at 6:51














0












0








0







Because you wrap your TodoForm component in withNamespaces HOC, getting the reference to your TodoForm is not as easy as calling ref={..}, since that returns reference to the HOC. To get the reference to your component, you have to leverage the innerRef parameter, when creating the HOC (see docs)



const TodoFormTranslated = withNamespaces("", {
innerRef: (ref) => VARIABLE_WHICH_WILL_NOW_CONTAIN_REF_TO_YOUR_EL = ref
})(TodoForm);


fast but working solution to your problem would look something like this: https://codesandbox.io/s/n55yvw1o2m



Maybe you don't want variables outside of your class, so I'll leave that to you in which way do you want to handle this. You can get inspiration for example from this post.






share|improve this answer













Because you wrap your TodoForm component in withNamespaces HOC, getting the reference to your TodoForm is not as easy as calling ref={..}, since that returns reference to the HOC. To get the reference to your component, you have to leverage the innerRef parameter, when creating the HOC (see docs)



const TodoFormTranslated = withNamespaces("", {
innerRef: (ref) => VARIABLE_WHICH_WILL_NOW_CONTAIN_REF_TO_YOUR_EL = ref
})(TodoForm);


fast but working solution to your problem would look something like this: https://codesandbox.io/s/n55yvw1o2m



Maybe you don't want variables outside of your class, so I'll leave that to you in which way do you want to handle this. You can get inspiration for example from this post.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 13:19









Matej P.Matej P.

4,19011633




4,19011633













  • have this helped solving your issue?

    – Matej P.
    Nov 16 '18 at 16:06











  • Unfortunately not. I was able to access the method in child component but I had no access to formik specific props like submitForm. So I decided to solve this issue with an additional props in TodoForm to trigger the form submit. This has the disadvantage that I need to write additional code but I see no other way.

    – user3481997
    Nov 16 '18 at 18:30











  • but you were able to run the submit method of the TodoForm then right? that what the question stated. You can post another question for the next issue.

    – Matej P.
    Nov 16 '18 at 21:59













  • OK, from that perspective the problem is solved. :-)

    – user3481997
    Nov 19 '18 at 6:51



















  • have this helped solving your issue?

    – Matej P.
    Nov 16 '18 at 16:06











  • Unfortunately not. I was able to access the method in child component but I had no access to formik specific props like submitForm. So I decided to solve this issue with an additional props in TodoForm to trigger the form submit. This has the disadvantage that I need to write additional code but I see no other way.

    – user3481997
    Nov 16 '18 at 18:30











  • but you were able to run the submit method of the TodoForm then right? that what the question stated. You can post another question for the next issue.

    – Matej P.
    Nov 16 '18 at 21:59













  • OK, from that perspective the problem is solved. :-)

    – user3481997
    Nov 19 '18 at 6:51

















have this helped solving your issue?

– Matej P.
Nov 16 '18 at 16:06





have this helped solving your issue?

– Matej P.
Nov 16 '18 at 16:06













Unfortunately not. I was able to access the method in child component but I had no access to formik specific props like submitForm. So I decided to solve this issue with an additional props in TodoForm to trigger the form submit. This has the disadvantage that I need to write additional code but I see no other way.

– user3481997
Nov 16 '18 at 18:30





Unfortunately not. I was able to access the method in child component but I had no access to formik specific props like submitForm. So I decided to solve this issue with an additional props in TodoForm to trigger the form submit. This has the disadvantage that I need to write additional code but I see no other way.

– user3481997
Nov 16 '18 at 18:30













but you were able to run the submit method of the TodoForm then right? that what the question stated. You can post another question for the next issue.

– Matej P.
Nov 16 '18 at 21:59







but you were able to run the submit method of the TodoForm then right? that what the question stated. You can post another question for the next issue.

– Matej P.
Nov 16 '18 at 21:59















OK, from that perspective the problem is solved. :-)

– user3481997
Nov 19 '18 at 6:51





OK, from that perspective the problem is solved. :-)

– user3481997
Nov 19 '18 at 6:51




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337227%2fhow-to-trigger-submit-from-parent%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma