Last active
August 29, 2015 14:22
-
-
Save aguestuser/d56d09515ace3e522d53 to your computer and use it in GitHub Desktop.
abortive attempt at combobox
This file contains hidden or 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
const BaseComponent = require('./BaseComponent'); | |
const Marty = require('marty'); | |
const { Combobox, configure } = require('react-widgets'); | |
configure.setGlobalizeInstance(window.globalize) | |
const lsApi = require('../api/lsApi'); | |
// unsurprisingly: this doesn't work | |
// produces error that says "combobox has no contents" | |
class SearchBox extends BaseComponent { | |
constructor(options){ | |
super(options); | |
this.state = { results: [] }; | |
this.bindAll('search'); // helper function from BaseComponent for binding methods | |
} | |
render(){ | |
return ( | |
<Combobox | |
className="searchBox" | |
data={this.state.results} | |
defaultValue='Search...' | |
onSubmit={ value => this.setState({ value })} | |
/> | |
); | |
} | |
search(query){ | |
lsApi.searchEntities(query) | |
.then(res => this.setState({results: res})) | |
.catch(err => { this.setState({results: ['Try again...']}); | |
}); | |
} | |
} | |
module.exports = Marty.createContainer(SearchBox); | |
// more suprisingly: this renders but looks butt-ugly | |
// text is unstyled | |
// there is a button that says "show combobox" | |
// and results appear as a bulletted unordered list | |
// I have bootstrap installed and it styles other things... | |
// What gives? Some dependency I'm not giving react-widgets that it needs? | |
// Do I need to be using LESS instead of SASS? | |
class SearchBox extends BaseComponent { | |
constructor(options){ | |
super(options); | |
this.colors = ['red', 'white', 'blue']; | |
this.state = { value: this.colors[0] }; | |
this.bindAll('search'); | |
} | |
render(){ | |
return ( | |
<Combobox | |
className="searchBox" | |
data={this.colors} | |
defaultValue='Search...' | |
onSubmit={ value => this.setState({ value })} | |
/> | |
); | |
} | |
} | |
module.exports = Marty.createContainer(SearchBox); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment