Submit wrong returned form Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!JavaScript post request like a form submitSubmitting a form by pressing enter without a submit buttonTwo submit buttons in one formPrevent users from submitting a form by hitting EnterHow to prevent buttons from submitting formsjQuery disable/enable submit buttonjQuery AJAX submit formCannot update during an existing state transitionReact Forms and EventsPass form input values to another component React
What does 丫 mean? 丫是什么意思?
i2c bus hangs in master RPi access to MSP430G uC ~1 in 1000 accesses
What does it mean that physics no longer uses mechanical models to describe phenomena?
What order were files/directories output in dir?
Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?
Can two people see the same photon?
How to change the tick of the color bar legend to black
What would you call this weird metallic apparatus that allows you to lift people?
Most effective melee weapons for arboreal combat? (pre-gunpowder technology)
What initially awakened the Balrog?
How can a team of shapeshifters communicate?
Project Euler #1 in C++
Special flights
In musical terms, what properties are varied by the human voice to produce different words / syllables?
Why weren't discrete x86 CPUs ever used in game hardware?
AppleTVs create a chatty alternate WiFi network
Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?
A term for a woman complaining about things/begging in a cute/childish way
What are the main differences between the original Stargate SG-1 and the Final Cut edition?
What does the writing on Poe's helmet say?
Why do early math courses focus on the cross sections of a cone and not on other 3D objects?
Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?
Is multiple magic items in one inherently imbalanced?
Delete free apps from library
Submit wrong returned form
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!JavaScript post request like a form submitSubmitting a form by pressing enter without a submit buttonTwo submit buttons in one formPrevent users from submitting a form by hitting EnterHow to prevent buttons from submitting formsjQuery disable/enable submit buttonjQuery AJAX submit formCannot update during an existing state transitionReact Forms and EventsPass form input values to another component React
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I hope you're having a nice week.
I'm getting objects from an axios.get request, kind of a research the user can submit. I'm displaying each object in a row of a table like this :
Result of the research
As you can see in the screenshot, each row is a form and the user can modify some inputs, then send back the row via the Save button when they modified it (or not).
The first problem is that when the user click on save for the first time without modifying it, the value of the state corresponding to the input is set to '' so the form return an empty state. Actually, I know why : when I render the input, I set the defaultValue to the value i got from the object, but don't attribute it to the corresponding state. How can I do that?
The second problem, and the one which is the most hard to solve from my point of view is when the user modifies the first row but clicks on the Save button of the second row, it gets the value from the first row... I think it's the onSubmit=this.handleSubmit of my form which fails because this refers to the same thing :
Clicking on Save on Row 2 returns the STAMP of the Row 1
Here is my function which renders a table from a Javascript Object getting from props :
GetLine= () =>
var datas = this.props.data; //get the datas (Array)
var ol=(Object.keys(datas)).length; //get length of the array
var rows=[]; //Will contain the returned
for(var i=0;i<ol;i++)
var data=datas[i]; //get the i line of the array
rows.push(
<tr key=i>
<td>
<form id=i onSubmit=this.handleSubmit></form>
</td>
<td>
<input form=i type="checkbox" name="name1" />
</td>
<td>
<input form=i type="submit" value="Save" className="btn btn-primary"/>
</td>
Object.keys(data).map(s => //maping through keys of the object
s=="VAT"
)
</tr>
)
return rows;
An here is my constructor with handleChange; handleSubmit and state :
class SearchBody extends Component{
constructor(props)
super(props);
this.state=
ORDERID:'',
EID:'',
ALLOCATIONID:'',
BROKERAGE:'',
AMOUNT:'',
SIDE:'',
STAMP:'',
VAT:'',
FTT:'',
MARKETFEES:'',
LOCALTAX:'',
OTHERTAX:'',
response:,
onCall : true
;
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
handleChange = (event) =>
event.preventDefault();
switch(event.target.name)
case "STAMP":
this.setState(STAMP : event.target.value);
case "VAT": this.setState(VAT : event.target.value);
case "FTT": this.setState(FTT : event.target.value);
case "MARKETFEES": this.setState(MARKETFEES : event.target.value);
case "LOCALTAX": this.setState(LOCALTAX : event.target.value);
case "OTHERTAX": this.setState(OTHERTAX : event.target.value);
handleSubmit = (event) =>
event.preventDefault();
console.log("row "+event.target.id);
console.log(this.state.STAMP);
I hope my problem is clear. Thanks everyone for you future answers.
reactjs forms html-table datatable submit
add a comment |
I hope you're having a nice week.
I'm getting objects from an axios.get request, kind of a research the user can submit. I'm displaying each object in a row of a table like this :
Result of the research
As you can see in the screenshot, each row is a form and the user can modify some inputs, then send back the row via the Save button when they modified it (or not).
The first problem is that when the user click on save for the first time without modifying it, the value of the state corresponding to the input is set to '' so the form return an empty state. Actually, I know why : when I render the input, I set the defaultValue to the value i got from the object, but don't attribute it to the corresponding state. How can I do that?
The second problem, and the one which is the most hard to solve from my point of view is when the user modifies the first row but clicks on the Save button of the second row, it gets the value from the first row... I think it's the onSubmit=this.handleSubmit of my form which fails because this refers to the same thing :
Clicking on Save on Row 2 returns the STAMP of the Row 1
Here is my function which renders a table from a Javascript Object getting from props :
GetLine= () =>
var datas = this.props.data; //get the datas (Array)
var ol=(Object.keys(datas)).length; //get length of the array
var rows=[]; //Will contain the returned
for(var i=0;i<ol;i++)
var data=datas[i]; //get the i line of the array
rows.push(
<tr key=i>
<td>
<form id=i onSubmit=this.handleSubmit></form>
</td>
<td>
<input form=i type="checkbox" name="name1" />
</td>
<td>
<input form=i type="submit" value="Save" className="btn btn-primary"/>
</td>
Object.keys(data).map(s => //maping through keys of the object
s=="VAT"
)
</tr>
)
return rows;
An here is my constructor with handleChange; handleSubmit and state :
class SearchBody extends Component{
constructor(props)
super(props);
this.state=
ORDERID:'',
EID:'',
ALLOCATIONID:'',
BROKERAGE:'',
AMOUNT:'',
SIDE:'',
STAMP:'',
VAT:'',
FTT:'',
MARKETFEES:'',
LOCALTAX:'',
OTHERTAX:'',
response:,
onCall : true
;
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
handleChange = (event) =>
event.preventDefault();
switch(event.target.name)
case "STAMP":
this.setState(STAMP : event.target.value);
case "VAT": this.setState(VAT : event.target.value);
case "FTT": this.setState(FTT : event.target.value);
case "MARKETFEES": this.setState(MARKETFEES : event.target.value);
case "LOCALTAX": this.setState(LOCALTAX : event.target.value);
case "OTHERTAX": this.setState(OTHERTAX : event.target.value);
handleSubmit = (event) =>
event.preventDefault();
console.log("row "+event.target.id);
console.log(this.state.STAMP);
I hope my problem is clear. Thanks everyone for you future answers.
reactjs forms html-table datatable submit
2 - I guess you need to create a new component to maintain state and render a row, that way you'll have a state for each row.
– Rafael Lima
Mar 22 at 11:58
Thank you Rafael Lima, it solved my second problem. I will try to resolve the first one. I keep you in touch if I find the answer
– xaoc2nd
Mar 22 at 15:04
add a comment |
I hope you're having a nice week.
I'm getting objects from an axios.get request, kind of a research the user can submit. I'm displaying each object in a row of a table like this :
Result of the research
As you can see in the screenshot, each row is a form and the user can modify some inputs, then send back the row via the Save button when they modified it (or not).
The first problem is that when the user click on save for the first time without modifying it, the value of the state corresponding to the input is set to '' so the form return an empty state. Actually, I know why : when I render the input, I set the defaultValue to the value i got from the object, but don't attribute it to the corresponding state. How can I do that?
The second problem, and the one which is the most hard to solve from my point of view is when the user modifies the first row but clicks on the Save button of the second row, it gets the value from the first row... I think it's the onSubmit=this.handleSubmit of my form which fails because this refers to the same thing :
Clicking on Save on Row 2 returns the STAMP of the Row 1
Here is my function which renders a table from a Javascript Object getting from props :
GetLine= () =>
var datas = this.props.data; //get the datas (Array)
var ol=(Object.keys(datas)).length; //get length of the array
var rows=[]; //Will contain the returned
for(var i=0;i<ol;i++)
var data=datas[i]; //get the i line of the array
rows.push(
<tr key=i>
<td>
<form id=i onSubmit=this.handleSubmit></form>
</td>
<td>
<input form=i type="checkbox" name="name1" />
</td>
<td>
<input form=i type="submit" value="Save" className="btn btn-primary"/>
</td>
Object.keys(data).map(s => //maping through keys of the object
s=="VAT"
)
</tr>
)
return rows;
An here is my constructor with handleChange; handleSubmit and state :
class SearchBody extends Component{
constructor(props)
super(props);
this.state=
ORDERID:'',
EID:'',
ALLOCATIONID:'',
BROKERAGE:'',
AMOUNT:'',
SIDE:'',
STAMP:'',
VAT:'',
FTT:'',
MARKETFEES:'',
LOCALTAX:'',
OTHERTAX:'',
response:,
onCall : true
;
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
handleChange = (event) =>
event.preventDefault();
switch(event.target.name)
case "STAMP":
this.setState(STAMP : event.target.value);
case "VAT": this.setState(VAT : event.target.value);
case "FTT": this.setState(FTT : event.target.value);
case "MARKETFEES": this.setState(MARKETFEES : event.target.value);
case "LOCALTAX": this.setState(LOCALTAX : event.target.value);
case "OTHERTAX": this.setState(OTHERTAX : event.target.value);
handleSubmit = (event) =>
event.preventDefault();
console.log("row "+event.target.id);
console.log(this.state.STAMP);
I hope my problem is clear. Thanks everyone for you future answers.
reactjs forms html-table datatable submit
I hope you're having a nice week.
I'm getting objects from an axios.get request, kind of a research the user can submit. I'm displaying each object in a row of a table like this :
Result of the research
As you can see in the screenshot, each row is a form and the user can modify some inputs, then send back the row via the Save button when they modified it (or not).
The first problem is that when the user click on save for the first time without modifying it, the value of the state corresponding to the input is set to '' so the form return an empty state. Actually, I know why : when I render the input, I set the defaultValue to the value i got from the object, but don't attribute it to the corresponding state. How can I do that?
The second problem, and the one which is the most hard to solve from my point of view is when the user modifies the first row but clicks on the Save button of the second row, it gets the value from the first row... I think it's the onSubmit=this.handleSubmit of my form which fails because this refers to the same thing :
Clicking on Save on Row 2 returns the STAMP of the Row 1
Here is my function which renders a table from a Javascript Object getting from props :
GetLine= () =>
var datas = this.props.data; //get the datas (Array)
var ol=(Object.keys(datas)).length; //get length of the array
var rows=[]; //Will contain the returned
for(var i=0;i<ol;i++)
var data=datas[i]; //get the i line of the array
rows.push(
<tr key=i>
<td>
<form id=i onSubmit=this.handleSubmit></form>
</td>
<td>
<input form=i type="checkbox" name="name1" />
</td>
<td>
<input form=i type="submit" value="Save" className="btn btn-primary"/>
</td>
Object.keys(data).map(s => //maping through keys of the object
s=="VAT"
)
</tr>
)
return rows;
An here is my constructor with handleChange; handleSubmit and state :
class SearchBody extends Component{
constructor(props)
super(props);
this.state=
ORDERID:'',
EID:'',
ALLOCATIONID:'',
BROKERAGE:'',
AMOUNT:'',
SIDE:'',
STAMP:'',
VAT:'',
FTT:'',
MARKETFEES:'',
LOCALTAX:'',
OTHERTAX:'',
response:,
onCall : true
;
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
handleChange = (event) =>
event.preventDefault();
switch(event.target.name)
case "STAMP":
this.setState(STAMP : event.target.value);
case "VAT": this.setState(VAT : event.target.value);
case "FTT": this.setState(FTT : event.target.value);
case "MARKETFEES": this.setState(MARKETFEES : event.target.value);
case "LOCALTAX": this.setState(LOCALTAX : event.target.value);
case "OTHERTAX": this.setState(OTHERTAX : event.target.value);
handleSubmit = (event) =>
event.preventDefault();
console.log("row "+event.target.id);
console.log(this.state.STAMP);
I hope my problem is clear. Thanks everyone for you future answers.
reactjs forms html-table datatable submit
reactjs forms html-table datatable submit
asked Mar 22 at 11:49
xaoc2ndxaoc2nd
11
11
2 - I guess you need to create a new component to maintain state and render a row, that way you'll have a state for each row.
– Rafael Lima
Mar 22 at 11:58
Thank you Rafael Lima, it solved my second problem. I will try to resolve the first one. I keep you in touch if I find the answer
– xaoc2nd
Mar 22 at 15:04
add a comment |
2 - I guess you need to create a new component to maintain state and render a row, that way you'll have a state for each row.
– Rafael Lima
Mar 22 at 11:58
Thank you Rafael Lima, it solved my second problem. I will try to resolve the first one. I keep you in touch if I find the answer
– xaoc2nd
Mar 22 at 15:04
2 - I guess you need to create a new component to maintain state and render a row, that way you'll have a state for each row.
– Rafael Lima
Mar 22 at 11:58
2 - I guess you need to create a new component to maintain state and render a row, that way you'll have a state for each row.
– Rafael Lima
Mar 22 at 11:58
Thank you Rafael Lima, it solved my second problem. I will try to resolve the first one. I keep you in touch if I find the answer
– xaoc2nd
Mar 22 at 15:04
Thank you Rafael Lima, it solved my second problem. I will try to resolve the first one. I keep you in touch if I find the answer
– xaoc2nd
Mar 22 at 15:04
add a comment |
1 Answer
1
active
oldest
votes
So the answer to the second problem is to create a new component to maintain state and render a row.
The answer to the first problem is this code :
<input ref=this[s]=React.createRef() form=i type="text" name=s defaultValue=data[s] onChange=this.handleChange/>
It will create a ref to the input which is independent because it's named after my key s.
When I want to access the ref, I have to do this :
this.s.current.value
Where s is the name of one of my attribute
And if s is unknown you can do this
Object.keys(data).map(s =>
console.log(this[s].current.value);
)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298957%2fsubmit-wrong-returned-form%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
So the answer to the second problem is to create a new component to maintain state and render a row.
The answer to the first problem is this code :
<input ref=this[s]=React.createRef() form=i type="text" name=s defaultValue=data[s] onChange=this.handleChange/>
It will create a ref to the input which is independent because it's named after my key s.
When I want to access the ref, I have to do this :
this.s.current.value
Where s is the name of one of my attribute
And if s is unknown you can do this
Object.keys(data).map(s =>
console.log(this[s].current.value);
)
add a comment |
So the answer to the second problem is to create a new component to maintain state and render a row.
The answer to the first problem is this code :
<input ref=this[s]=React.createRef() form=i type="text" name=s defaultValue=data[s] onChange=this.handleChange/>
It will create a ref to the input which is independent because it's named after my key s.
When I want to access the ref, I have to do this :
this.s.current.value
Where s is the name of one of my attribute
And if s is unknown you can do this
Object.keys(data).map(s =>
console.log(this[s].current.value);
)
add a comment |
So the answer to the second problem is to create a new component to maintain state and render a row.
The answer to the first problem is this code :
<input ref=this[s]=React.createRef() form=i type="text" name=s defaultValue=data[s] onChange=this.handleChange/>
It will create a ref to the input which is independent because it's named after my key s.
When I want to access the ref, I have to do this :
this.s.current.value
Where s is the name of one of my attribute
And if s is unknown you can do this
Object.keys(data).map(s =>
console.log(this[s].current.value);
)
So the answer to the second problem is to create a new component to maintain state and render a row.
The answer to the first problem is this code :
<input ref=this[s]=React.createRef() form=i type="text" name=s defaultValue=data[s] onChange=this.handleChange/>
It will create a ref to the input which is independent because it's named after my key s.
When I want to access the ref, I have to do this :
this.s.current.value
Where s is the name of one of my attribute
And if s is unknown you can do this
Object.keys(data).map(s =>
console.log(this[s].current.value);
)
edited Mar 22 at 16:43
answered Mar 22 at 16:31
xaoc2ndxaoc2nd
11
11
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298957%2fsubmit-wrong-returned-form%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2 - I guess you need to create a new component to maintain state and render a row, that way you'll have a state for each row.
– Rafael Lima
Mar 22 at 11:58
Thank you Rafael Lima, it solved my second problem. I will try to resolve the first one. I keep you in touch if I find the answer
– xaoc2nd
Mar 22 at 15:04