I'm currently working on a project using webpack and babel to build a project. I tried so many things as I can think of, but somehow onSubmit or onClick function do not work no matter how I bind those functions. Here is the code snippet of the code. Can anyone think of any possible reason?
Here's the code. I can't (usefully) make it a Stack Snippet because they don't allow form submissions.
export default class CommentForm extends React.Component {
constructor(props) {
super(props);
console.log("constructor");
}
onSubmit(e) {
e.preventDefault();
console.log("you clicked")
// 1. Take data from from form
let commentData = {
// commentName: this.refs.name.value,
commentBody: this.refs.content.value
}
// 2. Pass data back to App
this.props.addComment(commentData);
// 3. Reset the form
this.refs.commentForm.reset();
}
render() {
return (
<div className="commentForm">
<form name="comment" id="comment" onSubmit={this.onSubmit.bind(this)}>
<textarea className="commentText" ref="content" rows="10" placeholder="Comment"></textarea>
<button id="submit" type="submit">Add Value</button>
</form>
</div>
);
}
}
Here is a working fiddle, logging the values to the console. You don't need to use refs and the use of refs should be limited where possible.
Instead of refs, give the form elements a name and use
e.target.content.value
to access the values
https://jsfiddle.net/jq17t7uh/1/
Im really new to JavaScript and I started a new project that consists in a video player and editor. I have this modal Box: <div class="modal" id="myModal"> <div class="modal-header"> ...
Im really new to JavaScript and I started a new project that consists in a video player and editor. I have this modal Box: <div class="modal" id="myModal"> <div class="modal-header"> ...
#anotherdata=value#iamlookingforthis=226885#id=101&start=1 Given the string above how could I extract "iamlookingforthis=226885" in the string? value of it might change as this is dynamic. So, ...
#anotherdata=value#iamlookingforthis=226885#id=101&start=1 Given the string above how could I extract "iamlookingforthis=226885" in the string? value of it might change as this is dynamic. So, ...
I am trying to implement a checkbox as a button as described here: https://v4-alpha.getbootstrap.com/components/buttons/#checkbox-and-radio-buttons I am trying to listen to the the change event of ...
I am trying to implement a checkbox as a button as described here: https://v4-alpha.getbootstrap.com/components/buttons/#checkbox-and-radio-buttons I am trying to listen to the the change event of ...
I am looking at this example from openlayers themselves. You can see the source by clicking on the "kml-layer.js" link at the bottom. The source code when i do this looks like this: var map = new ...
I am looking at this example from openlayers themselves. You can see the source by clicking on the "kml-layer.js" link at the bottom. The source code when i do this looks like this: var map = new ...