Return an event just as any input.
See original GitHub issueI am making a form, with multiple fields, all my fields send a prop to the parent component, just like this: ChildComponent
function NameInput (props) {
return (
<React.Fragment>
<label htmlFor="username">Nombre de Usuario</label>
<input
className="form-control"
id="username"
name="username"
type="text"
placeholder="Enter username"
value={props.data}
onChange={props.handleChange}
/>
</React.Fragment>
)
};
The on change method, in the parent element, call action and add the new property to my state, with redux, and all the crazy things…
ParentComponent
handleChange = event => {
const {name, value} = event.target
this.props.addField({...this.props.user, [name] : value})
}
It works fine with any type of field, like names, email, etc etc… But this workflow doesn’t work with react-DatePicker, this is my current approach:
function birthInput(props) {
return (
<React.Fragment>
<label htmlFor="username">Año de nacimiento</label>
<DatePicker
name="nacimiento"
selected={props.data}
onChange={props.handleChange} />
</React.Fragment>
)
};
But, checking out what I get in my on change method, and found a simple date: Wed Mar 20 2019 16:00:39 GMT+0100 (hora estándar de Europa central)
Expected behaviour
Return the event from the input field.
Actual behavior
a dateObject
Steps to reproduce
Follow the example.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:10
Top Results From Across the Web
HTMLElement: input event - Web APIs | MDN
The input event fires when the value of an , , or element has been changed.
Read more >Events: change, input, cut, copy, paste
The input event triggers every time after a value is modified by the user. ... It's possible to copy/paste not just text, but...
Read more >Event when input value is changed by JavaScript?
Any time you change $input.value in code, call the code you want ... A simple way is just to trigger an input event...
Read more >Handling Events :: Eloquent JavaScript
Event listeners are called only when the event happens in the context of the object they are registered on. <button>Click me</button> <p>No handler...
Read more >The before and after Events - JustPy
Even if you have not assigned an input handler to that particular element, you may want to update the value anyway so it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I came across this issue of not being able to get the data i needed from the event of the input. I am creating each input dynamically and I am reading the name of the event.target to decide where to update my state. I found that I was able to hack it a bit and just create an object to mock the data I needed from the event.target object.
@josuevalrob las one is a good solution if you only have one date, i want to dynamically add from several datepickers, and its imposible without event target. Solution: one handler for every datepicker