Skip to content

Instantly share code, notes, and snippets.

@illmatix
Last active November 25, 2016 22:28
Show Gist options
  • Select an option

  • Save illmatix/2e6698e9e924cd7bc5f5d08a7d3eb01e to your computer and use it in GitHub Desktop.

Select an option

Save illmatix/2e6698e9e924cd7bc5f5d08a7d3eb01e to your computer and use it in GitHub Desktop.
/**
* @desc Primary jsx file for the fancy search react component.
* @author Chad Payne chad@simplesimple.ca
*/
var FancySearchInput = React.createClass({
getInitialState: function() {
var string;
if(typeof this.props.text !== 'undefined') {
string = this.props.text.length ? this.props.text : '';
} else {
string = '';
}
return {text: string};
},
shouldComponentUpdate(nextProps, nextState) {
var shouldComponentUpdate = this.props.text !== nextProps.text || this.state.text !== nextState.text;
return shouldComponentUpdate;
},
/**
* Input submit handler
*/
onChange: function (e) {
console.log('onChange');
console.log('')
this.setState({text: e.target.value });
// this.$form = jQuery(React.findDOMNode(this)).parents('.content').first().find('form#views-exposed-form-search-solr-solr-search-block');
// this.$form.find('.form-item-search-api-views-fulltext input').val(e.target.value).change();
},
/**
* Render sub components of the fancy search
*/
render: function () {
var value = this.state.text;
return <input type="text" className="fancy-search-text" value={value} onChange={this.onChange} placeholder="Search..." />;
}
});
module.exports = FancySearchInput;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment