Skip to content

Commit

Permalink
fix: set events after rendering a selectbox (fix #37) (#38)
Browse files Browse the repository at this point in the history
* fix: set events after rendering a selectbox (fix #37)

* chore: apply code review
  • Loading branch information
heenakwag authored Oct 29, 2019
1 parent eb864b6 commit 13b0ad7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/js/timepicker/selectbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ var Selectbox = snippet.defineClass(
};

if (this._element) {
domUtil.removeElement(this._element);
this._removeElement();
}

this._container.innerHTML = tmpl(context);
this._element = this._container.firstChild;
domUtil.on(this._element, 'change', this._onChangeHandler, this);
},

/**
Expand Down Expand Up @@ -131,8 +133,6 @@ var Selectbox = snippet.defineClass(
* @private
*/
_setEvents: function() {
domUtil.on(this._element, 'change', this._onChangeHandler, this);

this.on(
'changeItems',
function(items) {
Expand All @@ -149,8 +149,15 @@ var Selectbox = snippet.defineClass(
*/
_removeEvents: function() {
this.off();
},

/**
* Remove element
* @private
*/
_removeElement: function() {
domUtil.off(this._element, 'change', this._onChangeHandler, this);
domUtil.removeElement(this._element);
},

/**
Expand Down Expand Up @@ -203,7 +210,7 @@ var Selectbox = snippet.defineClass(
*/
destroy: function() {
this._removeEvents();
domUtil.removeElement(this._element);
this._removeElement();
this._container = this._items = this._selectedIndex = this._element = null;
}
}
Expand Down

0 comments on commit 13b0ad7

Please sign in to comment.