Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React,{Component} from 'react';
- import ReactDOM from 'react-dom';
- import ListItem from './ListItem';
- class FlavorForm extends React.Component {
- constructor(props) {
- super(props);
- this.state = {value: '', vardas: ''};
- // this.handleChange = this.handleChange.bind(this);
- //this.handleSubmit = this.handleSubmit.bind(this);
- // create a ref to store the textInput DOM element
- this.textInput = React.createRef();
- this.textInput2 = React.createRef();
- this.focusTextInput = this.focusTextInput.bind(this);
- }
- focusTextInput(event) {
- // Explicitly focus the text input using the raw DOM API
- // Note: we're accessing "current" to get the DOM node
- //this.textInput.current.focus();
- this.setState({vardas: this.textInput.current.value, value: this.textInput2.current.value});
- event.preventDefault();
- }
- /*
- handleChange(event) {
- this.setState({value: event.target.value});
- }
- handleChangex(event) {
- this.setState({value: event.target.vardas});
- }
- handleSubmit(event) {
- event.preventDefault();
- }
- */
- render() {
- return (
- <form>
- <label>
- Pick your favorite flavor:
- <select ref={this.textInput2}>
- <option value="apelsinu">apelsinu</option>
- <option value="citrinu">citrinu</option>
- <option value="mandarinu">mandarinu</option>
- <option value="mangu">mangu</option>
- </select>
- </label><br></br>
- <label>
- Vardas:
- <input type="text" ref={this.textInput} />
- </label>
- <label>{this.state.vardas} megsta {this.state.value} skoni</label><br></br>
- <input type="submit" value="Submit" onClick={this.focusTextInput} />
- </form>
- );
- }
- }
- ReactDOM.render(
- <FlavorForm />,
- document.getElementById('app')
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement