Last active
May 27, 2017 09:49
-
-
Save mhaagens/1d49f42c7e396f4649c8faa29d05c4eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
class AutoComplete extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
query: "" | |
} | |
} | |
_handleChange({target: {value}}) { | |
this.setState({ | |
query: value | |
}) | |
// Do api-call etc... | |
} | |
_getData = () => this.state.query | |
render() { | |
return <input | |
name="query" | |
placeholder="Autocomplete search..." | |
onChange={(e) => this._handleChange(e)} | |
value={this.state.query} | |
/> | |
} | |
} | |
class AnotherInput extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
query: "" | |
} | |
} | |
_handleChange({target: {value}}) { | |
this.setState({ | |
query: value | |
}) | |
// Do api-call etc... | |
} | |
_getData = () => this.state.query | |
render() { | |
return <input | |
name="query" | |
placeholder="Elasticsearch query..." | |
onChange={(e) => this._handleChange(e)} | |
value={this.state.query} | |
/> | |
} | |
} | |
class Form extends Component { | |
_getData() { | |
const children = ["autocomplete", "anotherinput"]; | |
const data = []; | |
for (let child of children) { | |
let obj = { | |
value: this[child]._getData(); | |
} | |
data[child] = obj; | |
} | |
console.log(data); | |
} | |
render() { | |
return <form style={{display: "flex", flexFlow: "column"}}> | |
<AutoComplete ref={e => this.autocomplete = e} /> | |
<AnotherInput ref={e => this.anotherinput = e} /> | |
<button onClick={(e) => { | |
e.preventDefault(); | |
this._getData(); | |
}}>Get data</button> | |
</form> | |
} | |
} | |
export default Form; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment