N
N
Nikita2019-08-17 14:59:05
JavaScript
Nikita, 2019-08-17 14:59:05

How to get input value during onSubmit event?

Can you tell me how to get input values?
Here, of course, an incorrect assignment occurs, because event refers to the form, and not to the input.
const payload = event.target.value
Full code:

import React from 'react'
import Input from '../../UI/Input/Input';
import Button from '../../UI/Button/Button';
import classes from './Main.module.css'

export default class Main extends React.Component {

  submitHandler = (event) => {
    event.preventDefault()
    const {getValueInput} = this.props
    const payload = event.target.value
    getValueInput(payload)
  }

  render() {

    return (
      <div className={classes.main}>
        <div className={classes.main_inner}>
          <div className={classes.form_outer}>
            <form onSubmit={this.submitHandler}>
              <Input />
              <Button>Добавить</Button>
            </form>
          </div>
        </div>
      </div>
    )
  }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
camelCaseVlad, 2019-08-17
@SonyFan23

If I understand you correctly, then:
Add state,

state = {
        inputEntry: '',
    }

in submitHandlerreplace const payload = event.target.valuewith const payload = this.state.inputEntry
and add a new handler to the input
handleInputChange = (e) => {
        this.setState({inputEntry: e.target.value})
    };

A
Antonio Solo, 2018-01-16
@solotony

RedirectMatch ^(.*?)/link1$ http://vash-site.ru/$1/link2

V
Viktor Taran, 2018-03-06
@shambler81

In your case, the regular season cannot be compiled because the minimum number of elements in it is to list stupidly all domains (msk|spb|uk|kz), and so on.
Or, for example, like this,
(.+[^/]) one or more characters but not a slash (that is, select everything up to the first slash)

RedirectMatch ^(.+[^/])/link1$ http://vash-site.ru/$1/link2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question