Skip to content

Instantly share code, notes, and snippets.

@gryzzly
Last active December 15, 2016 21:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gryzzly/50d6b78dd54bc2468d7a to your computer and use it in GitHub Desktop.
Save gryzzly/50d6b78dd54bc2468d7a to your computer and use it in GitHub Desktop.
Ember Debounced Input
//
// To be used like this:
//
//
// {{debounced-input
// placeholder="1000000"
// value=propertyName
// debounceWait=300 <-- debounce wait value
// fireAtStart=false <-- corresponds to Ember.run.debounce’s 4th param, if false, will run at the end of wait period
// class="form-control" <-- all regular text input attributes work
// name="price"
// }}
import Ember from 'ember';
export default Ember.TextField.extend({
debounceWait: 500,
fireAtStart: true,
_elementValueDidChange: function() {
Ember.run.debounce(this, this._setValue, this.debounceWait, this.fireAtStart);
},
_setValue: function () {
this.set('value', this.$().val());
}
});
@mitchmahan
Copy link

Where might you place this in the ember-cli hierarchy?

@gryzzly
Copy link
Author

gryzzly commented Dec 17, 2014

@mitchmahan for me it lives inside app/components/debounced-input.js and can be then used in templates without need to require it

@timmyomahony
Copy link

Where does the _elementValueDidChange method come from? I can't find it anywhere in the guides for TextField or TextSupportMixin or Component

@tylor
Copy link

tylor commented Jul 7, 2016

@timmyomahony Was curious too, spotted here: https://github.com/emberjs/ember.js/blob/v2.6.1/packages/ember-views/lib/mixins/text_support.js#L198 Makes me nervous to overwrite as it's most likely private...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment