---
title: "Ext.form.field.Number"
description: "xtype 为 numberfield 的 Ext JS 原生组件参考。"
---

> Documentation Index
> Fetch the complete documentation index at: https://ag.879818327.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Ext.form.field.Number

源码定义：`ext-all-debug.js:103498`。分类：表单与字段。

## 创建示例

```javascript
var component = Ext.create("Ext.form.field.Number", {
  xtype: "numberfield",
  allowDecimals: true,
  allowExponential: true,
  autoStripChars: false,
  baseChars: '0123456789',
  renderTo: Ext.getBody()
});
```

## 属性

| 属性 | 类型 | 默认值 | 说明 | 配置示例 |
| --- | --- | --- | --- | --- |
| `allowDecimals` | `Boolean` | `true` | 控制是否启用 `allowDecimals` 行为。 | `allowDecimals: true` |
| `allowExponential` | `Boolean` | `true` | 控制是否启用 `allowExponential` 行为。 | `allowExponential: true` |
| `autoStripChars` | `Boolean` | `false` | 控制是否启用 `autoStripChars` 行为。 | `autoStripChars: false` |
| `baseChars` | `String` | `'0123456789'` | 配置组件的 `baseChars` 选项。 | `baseChars: '0123456789'` |
| `decimalPrecision` | `Number` | `2` | 值规范化时保留的小数位数。 | `decimalPrecision: 2` |
| `decimalSeparator` | `Object/null` | `null` | 配置组件的 `decimalSeparator` 选项。 | `decimalSeparator: null` |
| `labelSeparator` | `String` | `''` | 配置组件的 `labelSeparator` 选项。 | `labelSeparator: ''` |
| `maxText` | `String` | `'The maximum value for this field is {0}'` | 配置 `maxText` 限制值。 | `maxText: 'The maximum value for this field is {0}'` |
| `maxValue` | `Mixed` | `Number.MAX_VALUE` | 允许设置的最大值。 | `maxValue: Number.MAX_VALUE` |
| `minText` | `String` | `'The minimum value for this field is {0}'` | 配置 `minText` 限制值。 | `minText: 'The minimum value for this field is {0}'` |
| `minValue` | `Mixed` | `Number.NEGATIVE_INFINITY` | 允许设置的最小值。 | `minValue: Number.NEGATIVE_INFINITY` |
| `nanText` | `String` | `'{0} is not a valid number'` | 配置组件的 `nanText` 选项。 | `nanText: '{0} is not a valid number'` |
| `negativeText` | `String` | `'The value cannot be negative'` | 配置组件的 `negativeText` 选项。 | `negativeText: 'The value cannot be negative'` |
| `step` | `Number` | `1` | 配置组件的 `step` 选项。 | `step: 1` |
| `submitLocaleSeparator` | `Boolean` | `true` | 控制是否启用 `submitLocaleSeparator` 行为。 | `submitLocaleSeparator: true` |

## 方法

| 方法 | 参数 | 说明 | 调用示例 |
| --- | --- | --- | --- |
| `initComponent` | `` | 初始化组件及其子项。 执行时会保留父类默认行为、更新 `decimalSeparator` 状态。源码涉及 `callParent()`、`setMinValue()`、`setMaxValue()`。 | `component.initComponent()` |
| `getErrors` | `value` | 读取并返回 `errors`。 执行时会保留父类默认行为。源码涉及 `callParent()`、`processRawValue()`、`getRawValue()`、`parseValue()`。 | `component.getErrors(...)` |
| `rawToValue` | `rawValue` | 将 `raw` 转换为 `value`。源码涉及 `fixPrecision()`、`parseValue()`。 | `component.rawToValue(...)` |
| `valueToRaw` | `value` | 将 `value` 转换为 `raw`。源码涉及 `parseValue()`、`fixPrecision()`。 | `component.valueToRaw(...)` |
| `getSubmitValue` | `` | 读取并返回 `submitValue`。 执行时会保留父类默认行为。源码涉及 `callParent()`。 | `component.getSubmitValue()` |
| `onChange` | `` | 处理 `change` 回调。 执行时会保留父类默认行为。源码涉及 `toggleSpinners()`、`callParent()`。 | `component.onChange()` |
| `toggleSpinners` | `` | 切换 `spinners`。源码涉及 `getValue()`。 | `component.toggleSpinners()` |
| `setMinValue` | `value` | 设置 `minValue`。 执行时会更新 `minValue`、`maskRe` 状态。源码涉及 `toggleSpinners()`。 | `component.setMinValue(...)` |
| `setMaxValue` | `value` | 设置 `maxValue`。 执行时会更新 `maxValue` 状态。源码涉及 `toggleSpinners()`。 | `component.setMaxValue(...)` |
| `parseValue` | `value` | 解析 `value`。 | `component.parseValue(...)` |
| `fixPrecision` | `value` | 处理 `fixPrecision` 操作。 | `component.fixPrecision(...)` |
| `beforeBlur` | `` | 在 `blur` 前执行预处理。 执行时会更新组件值。源码涉及 `rawToValue()`、`getRawValue()`、`setValue()`。 | `component.beforeBlur()` |

## 事件

源码中未找到该组件自身注册的事件；可监听继承事件。

Source: https://ag.879818327.xyz/ext/form/form-field-number/index.mdx
