Add VALUE_AS_NUMBER property to ol.dom.Input
This should be used when one want to bind a number instead of a string.
This commit is contained in:
@@ -11,6 +11,7 @@ goog.require('ol.Object');
|
||||
*/
|
||||
ol.dom.InputProperty = {
|
||||
VALUE: 'value',
|
||||
VALUE_AS_NUMBER: 'valueAsNumber',
|
||||
CHECKED: 'checked'
|
||||
};
|
||||
|
||||
@@ -44,6 +45,9 @@ ol.dom.Input = function(target) {
|
||||
goog.events.listen(this,
|
||||
ol.Object.getChangeEventType(ol.dom.InputProperty.VALUE),
|
||||
this.handleValueChanged_, false, this);
|
||||
goog.events.listen(this,
|
||||
ol.Object.getChangeEventType(ol.dom.InputProperty.VALUE_AS_NUMBER),
|
||||
this.handleValueAsNumberChanged_, false, this);
|
||||
goog.events.listen(this,
|
||||
ol.Object.getChangeEventType(ol.dom.InputProperty.CHECKED),
|
||||
this.handleCheckedChanged_, false, this);
|
||||
@@ -77,6 +81,19 @@ goog.exportProperty(
|
||||
ol.dom.Input.prototype.getValue);
|
||||
|
||||
|
||||
/**
|
||||
* Get the value of the input as a number.
|
||||
* @return {number|null|undefined} input value as number.
|
||||
*/
|
||||
ol.dom.Input.prototype.getValueAsNumber = function() {
|
||||
return /** @type {number} */ (this.get(ol.dom.InputProperty.VALUE_AS_NUMBER));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.dom.Input.prototype,
|
||||
'getValueAsNumber',
|
||||
ol.dom.Input.prototype.getValueAsNumber);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the value of the input.
|
||||
* @param {string} value Value.
|
||||
@@ -90,6 +107,19 @@ goog.exportProperty(
|
||||
ol.dom.Input.prototype.setValue);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the number value of the input.
|
||||
* @param {number} value Number value.
|
||||
*/
|
||||
ol.dom.Input.prototype.setValueAsNumber = function(value) {
|
||||
this.set(ol.dom.InputProperty.VALUE_AS_NUMBER, value);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.dom.Input.prototype,
|
||||
'setValueAsNumber',
|
||||
ol.dom.Input.prototype.setValueAsNumber);
|
||||
|
||||
|
||||
/**
|
||||
* Set whether or not a checkbox is checked.
|
||||
* @param {boolean} checked Checked.
|
||||
@@ -111,6 +141,7 @@ ol.dom.Input.prototype.handleInputChanged_ = function() {
|
||||
this.setChecked(this.target_.checked);
|
||||
} else {
|
||||
this.setValue(this.target_.value);
|
||||
this.setValueAsNumber(this.target_.valueAsNumber);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -129,3 +160,12 @@ ol.dom.Input.prototype.handleCheckedChanged_ = function() {
|
||||
ol.dom.Input.prototype.handleValueChanged_ = function() {
|
||||
this.target_.value = this.getValue();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.dom.Input.prototype.handleValueAsNumberChanged_ = function() {
|
||||
// firefox raises an exception if this.target_.valueAsNumber is set instead
|
||||
this.target_.value = this.getValueAsNumber();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user