Constructor

FieldNumber

new FieldNumber(opt_value, opt_min, opt_max, opt_precision, opt_validator)

Class for an editable number field.

Parameter

opt_value

(string or optional number)

The initial value of the field. Should cast to a number. Defaults to 0.

opt_min

Optional

(string or number)

Minimum value.

opt_max

Optional

(string or number)

Maximum value.

opt_precision

Optional

(string or number)

Precision for value.

opt_validator

Optional

function()

A function that is called to validate changes to the field's value. Takes in a number & returns a validated number, or null to abort the change.

Property

SERIALIZABLE

constant

boolean

Serializable fields are saved by the XML renderer, non-serializable fields are not. Editable fields should also be serializable.

Methods

fromJson

package   static

fromJson(options) returns Blockly.FieldNumber

Construct a FieldNumber from a JSON arg object.

Parameter

options

Object

A JSON object with options (value, min, max, and precision).

Value must not be null.

Returns

non-null Blockly.FieldNumber The new field instance.

doClassValidation_

protected

doClassValidation_(newValue) returns number

Ensure that the input value is a valid number (must fulfill the constraints placed on the field).

Parameter

newValue

(string or optional number)

The input value.

Returns

nullable number A valid number, or null if invalid.

setConstraints

setConstraints(min, max, precision)

Set the maximum, minimum and precision constraints on this field. Any of these properties may be undefiend or NaN to be disabled. Setting precision (usually a power of 10) enforces a minimum step between values. That is, the user's value will rounded to the closest multiple of precision. The least significant digit place is inferred from the precision. Integers values can be enforces by choosing an integer precision.

Parameter

min

(number, string, or undefined)

Minimum value.

max

(number, string, or undefined)

Maximum value.

precision

(number, string, or undefined)

Precision for value.