Created
May 28, 2014 00:54
-
-
Save jrhe/d519d23ffba65f20ba9e to your computer and use it in GitHub Desktop.
Ember Simple Form + Select2 value binding (untested)
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
| Ember.EasyForm.Select.reopen({ | |
| didInsertElement: function() { | |
| // Listen for select2 value changes. | |
| // Uses embers helper method to make sure this is bound correctly. | |
| // See: http://balinterdi.com/2014/05/09/ember-dot-run-dot-bind.html | |
| this.$().select2().on("change", Ember.run.bind(this, this.select2ValueChanged)); | |
| }, | |
| ... | |
| // When select2s value changes, update the components value | |
| select2ValueChanged: function(e) { | |
| this.set('value', e.val); | |
| }, | |
| // When the components value changes, update select2s value | |
| valueChanged: function(value) { | |
| this.$().select2("val", value); | |
| }.observes('value'), | |
| ... | |
| willDestroyElement: function() { | |
| // Unbind select2 change listener | |
| this.$().select2().off("change"); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment