简体   繁体   English

Sencha extjs setValue string to numberfield

[英]Sencha extjs setValue string to numberfield

I need to use numberfield for user input number. 我需要使用numberfield作为用户输入号码。 When I set string '123,555' it shows only 123 to numberfield. 当我设置字符串'123,555'时,它只显示123到数字字段。 But if I use textfield, it works as expected. 但是,如果我使用textfield,它会按预期工作。 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. 注意:我使用现代的sencha extjs 6。

You can use setRawValue() method of the numberfield. 您可以使用setRawValue()方法。 This will bypass all conversion and validation that you get when using setValue(). 这将绕过使用setValue()时获得的所有转换和验证。

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

Example: https://fiddle.sencha.com/fiddle/1iuu/preview 示例: 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, autoStripChars:false,
  2. disableKeyFilter: true disableKeyFilter:true
  3. stripCharsRe: false stripCharsRe:false
  4. maskRe: false 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 这里是一个覆盖 ,增加了useThousandSeperator到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. 提交的数字只允许数字(0-9和'。')如果您仍想在数字字段中允许','那么您可以通过以下属性进行设置。

baseChars :'0123456789,' baseChars:'0123456789,'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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