Skip to content

Commit

Permalink
keep ref on el and add test to it
Browse files Browse the repository at this point in the history
  • Loading branch information
tingpan committed Jun 5, 2015
1 parent f358d80 commit a3ecfaf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Select = (function(superClass) {
var idx, it, items, j, len, results1;
Select._tpl.select = "<div class=\"simple-select\">\n <span class=\"link-expand\" title=\"" + (this._t('all_options')) + "\">\n <i class=\"icon-caret-down\"><span>&#9662;</span></i>\n </span>\n <span class=\"link-clear\" title=\"" + (this._t('clear_selection')) + "\">\n <i class=\"icon-delete\"><span>&#10005;</span></i>\n </span>\n <div class=\"select-list\">\n <div class=\"loading\">" + (this._t('loading')) + "...</div>\n </div>\n</div>";
this.el = $(this.opts.el).hide();
this.el.data("select", this);
this.select = $(Select._tpl.select).data("select", this).addClass(this.opts.cls).insertBefore(this.el);
this.input = $(Select._tpl.input).attr("placeholder", this.el.data("placeholder") || this.opts.placeholder).prependTo(this.select);
this.list = this.select.find(".select-list");
Expand Down
9 changes: 9 additions & 0 deletions spec/select-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,12 @@ describe 'Simple Select', ->
expect(select.requireSelect).toBe(false)
expect(select.el.val()).toBe('')

it "keep reference in el", ->
selectEl.appendTo("body")
select = simple.select
el: $("#select-one")

expect(selectEl.data('select')).toBe(select)



10 changes: 9 additions & 1 deletion spec/select-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
select.input.blur();
return expect(select.el.val()).toBe('0');
});
return it('should always select default value if one option without value', function() {
it('should always select default value if one option without value', function() {
var select;
selectEl.append('<option value></option>');
selectEl.appendTo("body");
Expand All @@ -152,6 +152,14 @@
expect(select.requireSelect).toBe(false);
return expect(select.el.val()).toBe('');
});
return it("keep reference in el", function() {
var select;
selectEl.appendTo("body");
select = simple.select({
el: $("#select-one")
});
return expect(selectEl.data('select')).toBe(select);
});
});

}).call(this);
1 change: 1 addition & 0 deletions src/select.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Select extends SimpleModule
"""

@el = $(@opts.el).hide()
@el.data("select", @)
@select = $(Select._tpl.select)
.data("select", @)
.addClass(@opts.cls)
Expand Down

0 comments on commit a3ecfaf

Please sign in to comment.