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 = {
|
ol.dom.InputProperty = {
|
||||||
VALUE: 'value',
|
VALUE: 'value',
|
||||||
|
VALUE_AS_NUMBER: 'valueAsNumber',
|
||||||
CHECKED: 'checked'
|
CHECKED: 'checked'
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -44,6 +45,9 @@ ol.dom.Input = function(target) {
|
|||||||
goog.events.listen(this,
|
goog.events.listen(this,
|
||||||
ol.Object.getChangeEventType(ol.dom.InputProperty.VALUE),
|
ol.Object.getChangeEventType(ol.dom.InputProperty.VALUE),
|
||||||
this.handleValueChanged_, false, this);
|
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,
|
goog.events.listen(this,
|
||||||
ol.Object.getChangeEventType(ol.dom.InputProperty.CHECKED),
|
ol.Object.getChangeEventType(ol.dom.InputProperty.CHECKED),
|
||||||
this.handleCheckedChanged_, false, this);
|
this.handleCheckedChanged_, false, this);
|
||||||
@@ -77,6 +81,19 @@ goog.exportProperty(
|
|||||||
ol.dom.Input.prototype.getValue);
|
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.
|
* Sets the value of the input.
|
||||||
* @param {string} value Value.
|
* @param {string} value Value.
|
||||||
@@ -90,6 +107,19 @@ goog.exportProperty(
|
|||||||
ol.dom.Input.prototype.setValue);
|
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.
|
* Set whether or not a checkbox is checked.
|
||||||
* @param {boolean} checked Checked.
|
* @param {boolean} checked Checked.
|
||||||
@@ -111,6 +141,7 @@ ol.dom.Input.prototype.handleInputChanged_ = function() {
|
|||||||
this.setChecked(this.target_.checked);
|
this.setChecked(this.target_.checked);
|
||||||
} else {
|
} else {
|
||||||
this.setValue(this.target_.value);
|
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() {
|
ol.dom.Input.prototype.handleValueChanged_ = function() {
|
||||||
this.target_.value = this.getValue();
|
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