需求:Ext.form.field.Text 或 NumberField 只能輸入數字,保留兩位小數,隱藏右側上下箭頭(spinner)。
{
xtype: 'textfield',
inputType: 'number', // HTML5 原生數字輸入,移動端喚起數字鍵盤
maskRe: /[\d.]/, // 僅允許數字和小數點
regex: /^\d+(\.\d{1,2})?$/, // 驗證:整數或最多兩位小數
regexText: '請輸入數字,最多兩位小數',
// 隱藏 spinner(需 CSS)
style: '-webkit-appearance: none; margin: 0;' // 針對 WebKit
}
CSS 全局隱藏:
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type=number] { -moz-appearance: textfield; } /* Firefox */
{
xtype: 'numberfield',
decimalPrecision: 2, // 兩位小數
hideTrigger: true, // ExtJS 6+ 支持隱藏觸發器
// 若版本不支持 hideTrigger,用 CSS 隱藏 .x-form-spinner
}
hideTrigger: true 最簡潔。.x-form-spinner-up/down。