disable when no input is in write data form

pull/1537/head
Jade McGough 2017-05-25 23:23:45 -07:00
parent c82a64cad9
commit c091ea7edc
1 changed files with 14 additions and 7 deletions

View File

@ -8,12 +8,14 @@ class WriteDataForm extends Component {
super(props) super(props)
this.state = { this.state = {
selectedDatabase: null, selectedDatabase: null,
inputContent: '',
} }
this.handleSelectDatabase = ::this.handleSelectDatabase this.handleSelectDatabase = ::this.handleSelectDatabase
this.handleWrite = ::this.handleWrite this.handleSubmit = ::this.handleSubmit
this.handleClickOutside = ::this.handleClickOutside this.handleClickOutside = ::this.handleClickOutside
this.handleKeyUp = ::this.handleKeyUp this.handleKeyUp = ::this.handleKeyUp
this.handleEdit = ::this.handleEdit
} }
handleSelectDatabase(item) { handleSelectDatabase(item) {
@ -32,15 +34,19 @@ class WriteDataForm extends Component {
} }
} }
handleWrite() { handleSubmit() {
const {onClose, source, writeData} = this.props const {onClose, source, writeData} = this.props
const {selectedDatabase} = this.state const {inputContent, selectedDatabase} = this.state
writeData(source, selectedDatabase, this.editor.value).then(() => onClose()) writeData(source, selectedDatabase, inputContent).then(() => onClose())
}
handleEdit(e) {
this.setState({inputContent: e.target.value.trim()})
} }
render() { render() {
const {onClose, errorThrown} = this.props const {onClose, errorThrown} = this.props
const {selectedDatabase} = this.state const {inputContent, selectedDatabase} = this.state
return ( return (
<div className="write-data-form"> <div className="write-data-form">
@ -63,8 +69,8 @@ class WriteDataForm extends Component {
autoComplete="off" autoComplete="off"
spellCheck="false" spellCheck="false"
placeholder="<measurement>,<tag_key>=<tag_value> <field_key>=<field_value>" placeholder="<measurement>,<tag_key>=<tag_value> <field_key>=<field_value>"
ref={editor => this.editor = editor}
onKeyUp={this.handleKeyUp} onKeyUp={this.handleKeyUp}
onChange={this.handleEdit}
autoFocus={true} autoFocus={true}
/> />
<div className="write-data-form--footer"> <div className="write-data-form--footer">
@ -79,7 +85,8 @@ class WriteDataForm extends Component {
</span> </span>
<button <button
className="btn btn-sm btn-primary write-data-form--submit" className="btn btn-sm btn-primary write-data-form--submit"
onClick={this.handleWrite} onClick={this.handleSubmit}
disabled={!inputContent}
> >
Write Write
</button> </button>