mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Validate newValue parameter in setValue (#2392)
* Validate newValue parameter in setValue * bugfix * alternate fix * test * cleanup
This commit is contained in:
@@ -621,6 +621,12 @@ Blockly.Field.prototype.setValue = function(newValue) {
|
||||
// No change if null.
|
||||
return;
|
||||
}
|
||||
// Validate input.
|
||||
var validated = this.callValidator(newValue);
|
||||
if (validated !== null) {
|
||||
newValue = validated;
|
||||
}
|
||||
// Check for change.
|
||||
var oldValue = this.getValue();
|
||||
if (oldValue == newValue) {
|
||||
return;
|
||||
|
||||
@@ -45,10 +45,10 @@ goog.require('Blockly.FieldTextInput');
|
||||
*/
|
||||
Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision,
|
||||
opt_validator) {
|
||||
this.setConstraints(opt_min, opt_max, opt_precision);
|
||||
opt_value = (opt_value && !isNaN(opt_value)) ? String(opt_value) : '0';
|
||||
Blockly.FieldNumber.superClass_.constructor.call(
|
||||
this, opt_value, opt_validator);
|
||||
this.setConstraints(opt_min, opt_max, opt_precision);
|
||||
};
|
||||
goog.inherits(Blockly.FieldNumber, Blockly.FieldTextInput);
|
||||
|
||||
@@ -95,7 +95,6 @@ Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) {
|
||||
this.min_ = isNaN(min) ? -Infinity : min;
|
||||
max = parseFloat(max);
|
||||
this.max_ = isNaN(max) ? Infinity : max;
|
||||
this.setValue(this.callValidator(this.getValue()));
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user