Skip to content

Instantly share code, notes, and snippets.

@tbrd
Last active August 29, 2015 13:56
Show Gist options
  • Save tbrd/8955436 to your computer and use it in GitHub Desktop.
Save tbrd/8955436 to your computer and use it in GitHub Desktop.
A search form component for Flight
define(function (require) {
'use strict';
/**
* Module dependencies
*/
var defineComponent = require('flight/lib/component');
/**
* Module exports
*/
return defineComponent(searchForm);
/**
* Module function
*/
function searchForm() {
this.defaultAttrs({
keywordInputSelector: '.js-keywords'
});
this.after('initialize', function () {
this.on('submit', this.handleSubmit);
});
this.handleSubmit = function (event) {
// prevent submit event from bubbling
event.preventDefault();
// get the value of .js-keywords
var keywords = this.select('keywordInputSelector').val();
// broadcast keywords
this.trigger('ui-keywords', {
keywords: keywords
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment