cycle through array of records in react-final-form












0














I have a form in a component that will have a few records to cycle through. the records are called and stored in the redux store on componentdidMount. I am having trouble "cycling" through the records on my form. I can set initial values easily enough but what is the best approach when the user clicks next to have react-final-form re initialize with the data from the next record in the collection (data[x])?



    export type IFormDataStatProps = {
data: Array<FormData>;
}

export interface IFormDataDispatchProps {
getData: () => void;
}

type IFormDataPageProps = IFormDataStatProps & IFormDataDispatchProps;

class FormPage extends React.Component<IFormDataPageProps> {

constructor(props: IFormDataPageProps) {
super(props);
}

public componenetDidMount() {
this.props.getData();
}

onSubmit = (values) => {
window.alerty(JSON.stringify(values, undefined, 2));
}

nextRecord = () => {
//something here to reinitialize the form with data from next array position (data[1]). There might be something built into react-final-form to do this.
}

public render() {
return (
<Form
onSubmit={this.onSubmit}
initialVaues={{
firstName: data[0].firstName,
lastName: data[0].lastName
}}
render={({ handleSubmit, form, submitting, pristine, values}) => (
<Field
name="firstName"
component="input"
/>

<Field
name="lastName"
component="input"
/>

<button type="submit">Save</button>
<button onClick={this.nextRecord}>Next</button>
)}
)
}
}









share|improve this question
























  • a Minimal, Complete, and Verifiable example would help
    – Sagiv b.g
    Nov 12 '18 at 15:25










  • I added a code block for example.
    – Chris P
    Nov 12 '18 at 16:36
















0














I have a form in a component that will have a few records to cycle through. the records are called and stored in the redux store on componentdidMount. I am having trouble "cycling" through the records on my form. I can set initial values easily enough but what is the best approach when the user clicks next to have react-final-form re initialize with the data from the next record in the collection (data[x])?



    export type IFormDataStatProps = {
data: Array<FormData>;
}

export interface IFormDataDispatchProps {
getData: () => void;
}

type IFormDataPageProps = IFormDataStatProps & IFormDataDispatchProps;

class FormPage extends React.Component<IFormDataPageProps> {

constructor(props: IFormDataPageProps) {
super(props);
}

public componenetDidMount() {
this.props.getData();
}

onSubmit = (values) => {
window.alerty(JSON.stringify(values, undefined, 2));
}

nextRecord = () => {
//something here to reinitialize the form with data from next array position (data[1]). There might be something built into react-final-form to do this.
}

public render() {
return (
<Form
onSubmit={this.onSubmit}
initialVaues={{
firstName: data[0].firstName,
lastName: data[0].lastName
}}
render={({ handleSubmit, form, submitting, pristine, values}) => (
<Field
name="firstName"
component="input"
/>

<Field
name="lastName"
component="input"
/>

<button type="submit">Save</button>
<button onClick={this.nextRecord}>Next</button>
)}
)
}
}









share|improve this question
























  • a Minimal, Complete, and Verifiable example would help
    – Sagiv b.g
    Nov 12 '18 at 15:25










  • I added a code block for example.
    – Chris P
    Nov 12 '18 at 16:36














0












0








0







I have a form in a component that will have a few records to cycle through. the records are called and stored in the redux store on componentdidMount. I am having trouble "cycling" through the records on my form. I can set initial values easily enough but what is the best approach when the user clicks next to have react-final-form re initialize with the data from the next record in the collection (data[x])?



    export type IFormDataStatProps = {
data: Array<FormData>;
}

export interface IFormDataDispatchProps {
getData: () => void;
}

type IFormDataPageProps = IFormDataStatProps & IFormDataDispatchProps;

class FormPage extends React.Component<IFormDataPageProps> {

constructor(props: IFormDataPageProps) {
super(props);
}

public componenetDidMount() {
this.props.getData();
}

onSubmit = (values) => {
window.alerty(JSON.stringify(values, undefined, 2));
}

nextRecord = () => {
//something here to reinitialize the form with data from next array position (data[1]). There might be something built into react-final-form to do this.
}

public render() {
return (
<Form
onSubmit={this.onSubmit}
initialVaues={{
firstName: data[0].firstName,
lastName: data[0].lastName
}}
render={({ handleSubmit, form, submitting, pristine, values}) => (
<Field
name="firstName"
component="input"
/>

<Field
name="lastName"
component="input"
/>

<button type="submit">Save</button>
<button onClick={this.nextRecord}>Next</button>
)}
)
}
}









share|improve this question















I have a form in a component that will have a few records to cycle through. the records are called and stored in the redux store on componentdidMount. I am having trouble "cycling" through the records on my form. I can set initial values easily enough but what is the best approach when the user clicks next to have react-final-form re initialize with the data from the next record in the collection (data[x])?



    export type IFormDataStatProps = {
data: Array<FormData>;
}

export interface IFormDataDispatchProps {
getData: () => void;
}

type IFormDataPageProps = IFormDataStatProps & IFormDataDispatchProps;

class FormPage extends React.Component<IFormDataPageProps> {

constructor(props: IFormDataPageProps) {
super(props);
}

public componenetDidMount() {
this.props.getData();
}

onSubmit = (values) => {
window.alerty(JSON.stringify(values, undefined, 2));
}

nextRecord = () => {
//something here to reinitialize the form with data from next array position (data[1]). There might be something built into react-final-form to do this.
}

public render() {
return (
<Form
onSubmit={this.onSubmit}
initialVaues={{
firstName: data[0].firstName,
lastName: data[0].lastName
}}
render={({ handleSubmit, form, submitting, pristine, values}) => (
<Field
name="firstName"
component="input"
/>

<Field
name="lastName"
component="input"
/>

<button type="submit">Save</button>
<button onClick={this.nextRecord}>Next</button>
)}
)
}
}






reactjs react-redux react-final-form






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 16:36

























asked Nov 12 '18 at 15:11









Chris P

105




105












  • a Minimal, Complete, and Verifiable example would help
    – Sagiv b.g
    Nov 12 '18 at 15:25










  • I added a code block for example.
    – Chris P
    Nov 12 '18 at 16:36


















  • a Minimal, Complete, and Verifiable example would help
    – Sagiv b.g
    Nov 12 '18 at 15:25










  • I added a code block for example.
    – Chris P
    Nov 12 '18 at 16:36
















a Minimal, Complete, and Verifiable example would help
– Sagiv b.g
Nov 12 '18 at 15:25




a Minimal, Complete, and Verifiable example would help
– Sagiv b.g
Nov 12 '18 at 15:25












I added a code block for example.
– Chris P
Nov 12 '18 at 16:36




I added a code block for example.
– Chris P
Nov 12 '18 at 16:36












0






active

oldest

votes











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%2f53265005%2fcycle-through-array-of-records-in-react-final-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53265005%2fcycle-through-array-of-records-in-react-final-form%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.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values