Advertisement
Qpel

g3g

Nov 14th, 2019
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React,{Component} from 'react';
  2. import ReactDOM from 'react-dom';
  3. import ListItem from './ListItem';
  4. class FlavorForm extends React.Component {
  5.   constructor(props) {
  6.     super(props);
  7.     this.state = {value: '', vardas: ''};
  8.  
  9.    // this.handleChange = this.handleChange.bind(this);
  10.     //this.handleSubmit = this.handleSubmit.bind(this);
  11.     // create a ref to store the textInput DOM element
  12.     this.textInput = React.createRef();
  13.     this.textInput2 = React.createRef();
  14.     this.focusTextInput = this.focusTextInput.bind(this);
  15.    
  16.   }
  17.  
  18.   focusTextInput(event) {
  19.     // Explicitly focus the text input using the raw DOM API
  20.     // Note: we're accessing "current" to get the DOM node
  21.     //this.textInput.current.focus();
  22.     this.setState({vardas: this.textInput.current.value, value: this.textInput2.current.value});
  23.     event.preventDefault();
  24.   }
  25.   /*
  26.   handleChange(event) {
  27.     this.setState({value: event.target.value});
  28.   }
  29.  
  30.  
  31.   handleChangex(event) {
  32.     this.setState({value: event.target.vardas});
  33.   }
  34.  
  35.   handleSubmit(event) {
  36.  
  37.     event.preventDefault();
  38.   }
  39. */
  40.   render() {
  41.     return (
  42.       <form>
  43.         <label>
  44.           Pick your favorite flavor:
  45.           <select ref={this.textInput2}>
  46.             <option value="apelsinu">apelsinu</option>
  47.             <option value="citrinu">citrinu</option>
  48.             <option value="mandarinu">mandarinu</option>
  49.             <option value="mangu">mangu</option>
  50.           </select>
  51.         </label><br></br>
  52.         <label>
  53.           Vardas:
  54.           <input type="text" ref={this.textInput} />
  55.         </label>
  56.         <label>{this.state.vardas} megsta {this.state.value} skoni</label><br></br>
  57.  
  58.         <input type="submit" value="Submit"  onClick={this.focusTextInput} />
  59.       </form>
  60.     );
  61.   }
  62. }
  63.  
  64. ReactDOM.render(
  65.   <FlavorForm />,
  66.   document.getElementById('app')
  67. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement