assets/js/romo/select.js in romo-0.19.5 vs assets/js/romo/select.js in romo-0.19.6
- old
+ new
@@ -11,23 +11,21 @@
this.defaultCaretPaddingPx = 5;
this.defaultCaretPosition = 'right'
this.doInit();
this._bindElem();
- this.doRefreshUI();
+ this.doSetValue(this.elem[0].value);
+
if (this.elem.attr('id') !== undefined) {
$('label[for="'+this.elem.attr('id')+'"]').on('click', $.proxy(function(e) {
this.romoSelectDropdown.elem.focus();
}, this));
}
$(window).on("pageshow", $.proxy(function(e) {
- var selectedVal = this.romoSelectDropdown.selectedItemValue();
- if (selectedVal !== this.elem[0].value) {
- this.doSetValue(selectedVal);
- }
+ this._refreshUI();
}, this));
this.elem.on('select:triggerSetValue', $.proxy(function(e, value) {
this.doSetValue(value)
}, this));
@@ -37,21 +35,14 @@
RomoSelect.prototype.doInit = function() {
// override as needed
}
-RomoSelect.prototype.doRefreshUI = function() {
- var text = this.romoSelectDropdown.selectedItemText();
- if (text === '') {
- text = ' '
- }
- this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
-}
-
RomoSelect.prototype.doSetValue = function(value) {
- this.romoSelectDropdown.doSetNewValue(value);
- this._setNewValue(value);
+ this.romoSelectDropdown.doSetSelectedItem(value);
+ this._setValue(value);
+ this._refreshUI();
}
/* private */
RomoSelect.prototype._bindElem = function() {
@@ -64,16 +55,10 @@
this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupOpen', []);
}, this));
this.elem.on('select:triggerPopupClose', $.proxy(function(e) {
this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupClose', []);
}, this));
-
-
- var presetVal = this.elem[0].value;
- if (presetVal !== '') {
- this.doSetValue(presetVal);
- }
}
RomoSelect.prototype._bindSelectDropdown = function() {
this.romoSelectDropdown = this._buildSelectDropdownElem().romoSelectDropdown(this.elem)[0];
@@ -85,16 +70,20 @@
}, this));
this.romoSelectDropdown.elem.on('selectDropdown:dropdown:popupClose', $.proxy(function(e, dropdown, selectDropdown) {
this.elem.trigger('select:dropdown:popupClose', [dropdown, this]);
}, this));
- this.romoSelectDropdown.elem.on('selectDropdown:itemSelected', $.proxy(function(e, newValue, prevValue, selectDropdown) {
+ this.romoSelectDropdown.elem.on('selectDropdown:itemSelected', $.proxy(function(e, itemValue, itemDisplayText, selectDropdown) {
this.romoSelectDropdown.elem.focus();
- this.elem.trigger('select:itemSelected', [newValue, prevValue, this]);
+ this.elem.trigger('select:itemSelected', [itemValue, itemDisplayText, this]);
}, this));
+ this.romoSelectDropdown.elem.on('selectDropdown:newItemSelected', $.proxy(function(e, itemValue, itemDisplayText, selectDropdown) {
+ this._setValue(itemValue);
+ this._refreshUI();
+ this.elem.trigger('select:newItemSelected', [itemValue, itemDisplayText, this]);
+ }, this));
this.romoSelectDropdown.elem.on('selectDropdown:change', $.proxy(function(e, newValue, prevValue, selectDropdown) {
- this._setNewValue(newValue);
this.elem.trigger('change');
this.elem.trigger('select:change', [newValue, prevValue, this]);
}, this));
}
@@ -187,19 +176,32 @@
}
return romoSelectDropdownElem;
}
+RomoSelect.prototype._setValue = function(value) {
+ var prevOptElem = this.elem.find('OPTION[value="'+this.elem[0].value+'"]');
+ var newOptElem = this.elem.find('OPTION[value="'+value+'"]');
+
+ prevOptElem.removeAttr('selected');
+ prevOptElem.prop('selected', false);
+ newOptElem.attr('selected', 'selected');
+ newOptElem.prop('selected', true);
+}
+
+RomoSelect.prototype._refreshUI = function() {
+ var text = this.elem.find('OPTION[selected="selected"]').text().trim();
+ if (text === '') {
+ text = ' '
+ }
+ this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
+}
+
RomoSelect.prototype._onCaretClick = function(e) {
if (this.elem.prop('disabled') === false) {
this.romoSelectDropdown.elem.focus();
this.elem.trigger('select:triggerPopupOpen');
}
-}
-
-RomoSelect.prototype._setNewValue = function(newValue) {
- this.elem[0].value = newValue;
- this.doRefreshUI();
}
RomoSelect.prototype._getCaretPaddingPx = function() {
return (
this.elem.data('romo-select-caret-padding-px') ||