You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
FieldNumber constructor ignores constraints if a config object is present #3970
When constructing a number field, one passes in 4 constraints, a validator and a config object. If the config object is present, the constructor constraints are ignored, even if the config object does not replace them.
To Reproduce
.appendField(newBlockly.FieldNumber(this.state.minLength.value,0,Number.MAX_SAFE_INTEGER,1,(value)=>{if(this.state.maxLength.enabled&&value>this.state.maxLength.value){returnnull}this.state.minLength.value=valuereturnvalue},{tooltip: 'Minimum length of the string'}))
This constructed field ignores the precision setting of 1. FieldNumber's constructor (lines 69-74) has this logic which produces the bug:
Blockly.FieldNumber.superClass_.constructor.call(this,opt_value||0,opt_validator,opt_config);if(!opt_config){// Only do one kind of configuration or the other.this.setConstraints(opt_min,opt_max,opt_precision);}
Expected behavior
Constructor constraints should be used unless overridden in the config.
Ideally one would have a separate constructor with just the config object providing the constraints and validators.
Desktop (please complete the following information):
Here's some more specific steps for anyone who wants to work on this issue:
Add a warning to the FieldNumber constructor if both a constraints and a config option are present. The warning should say something about how the constructor constraints will be ignored/overwritten if a config is present. You can use console.warn for this.
Hi! I'd like to work on this. The steps in the comments are really clear - I'll add the console.warn when both constraint args and a config object are passed, plus update the docs. Should have a PR up soon.
Activity
mattbishop commentedon Jun 14, 2020
This may be a documentation issue as the internal comment suggests, though it would be helpful to throw an error explaining the rule too.
zspriggs commentedon Sep 25, 2026
Here's some more specific steps for anyone who wants to work on this issue:
console.warnfor this.25x55a0405-glitch commentedon Sep 29, 2026
Hi! I'd like to work on this. The steps in the comments are really clear - I'll add the console.warn when both constraint args and a config object are passed, plus update the docs. Should have a PR up soon.
zspriggs commentedon Sep 29, 2026
@25x55a0405-glitch Sounds great, thanks for working on it!
Anshmittal86 commentedon Nov 9, 2026
Hi @25x55a0405-glitch, are you still working on this? If not, I’d be happy to pick it up. No worries either way!