5

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.

Phon Soyang
  • 1,303
  • 2
  • 9
  • 17
  • 3
    @DavidR I guess he is working on thousand separator. – UDID Oct 18 '16 at 09:06
  • 2
    @Phon , NumberField doesn't support formatting and in this case you have to use `textfield`. A similar question I found here please check for solution. http://stackoverflow.com/questions/7413188/thousands-separators-in-ext-form-numberfield – UDID Oct 18 '16 at 09:06
  • 1
    @DavidR Ya, hehe, Actually I Was preparing a fiddle for you. [Future Reference ] https://fiddle.sencha.com/#fiddle/1imq – UDID Oct 18 '16 at 09:11
  • @UDID Ha haa :D – David R Oct 18 '16 at 09:14
  • You would need to manually convert it to a number first, see http://stackoverflow.com/questions/18405178/parsing-numbers-with-a-comma-decimal-separator-in-javascript – serg Oct 18 '16 at 16:28

3 Answers3

1

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.

Tom O.
  • 5,730
  • 2
  • 21
  • 35
  • I use sencha extjs 6 modern. setRawValue() is not working. – Phon Soyang Jan 03 '17 at 08:54
  • My mistake; I missed the note at the end of your question. I recommend adding the 'extjs6-modern' or 'extjs6' tag to your question. – Tom O. Jan 03 '17 at 14:12
  • Thanks, I updated my question. Have you got any idea with this? – Phon Soyang Jan 04 '17 at 02:18
  • Do you need the comma to display in the numberfield? Or are you only trying to set the value of the numberfield using a string formatted like a number? If you need the comma to show up in the in the field then I think your only option is to use a textfield with some validation. If you're just trying to set the field with a string formatted like a number then I have a solution that will work. – Tom O. Jan 04 '17 at 15:19
  • Actually, I want the comma to display in the numberfield. anw, I fixed it alr. – Phon Soyang Jan 11 '17 at 03:27
1

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

Akin Okegbile
  • 1,108
  • 19
  • 36
0

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,'