简体   繁体   中英

Sencha extjs setValue string to numberfield

I need to use numberfield for user input number. When I set string '123,555' it shows only 123 to numberfield. But if I use textfield, it works as expected. I use this for thousand separation.

xtype: 'numberfield',
itemId: 'payment1',
cls : 'txtAlignRight',
flex : 4,
value:'0',
autoComplete: false,
autoCorrect: false,
clearIcon: false,
originalValue: true,
required: true,
maxLength: 15,

//------------------
num.setValue('123,555')
//result = 123

Is there any solutions to do it? Thanks in advance. Note: I use sencha extjs 6 modern.

You can use setRawValue() method of the numberfield. This will bypass all conversion and validation that you get when using setValue().

Documentation: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Number-method-setRawValue

Example: https://fiddle.sencha.com/fiddle/1iuu/preview

This will merely set the value and will not work to increment / decrement using buttons the way this is coded now.

TO change which chars are allowed. You might wanna change these properties
The way these properties work is here

  1. autoStripChars: false,
  2. disableKeyFilter: true
  3. stripCharsRe: false
  4. maskRe: false

Sounds like you're needing to add Formatting to a number field.

here is an override that adds the useThousandSeperator to a numberfield

Ext.util.Format

Number filed allow only digit (0-9 and '.') And if you still want to allow ',' in numberfield then you can set by following propertie.

baseChars :'0123456789,'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM