【问题标题】:Add exception to min/max value in numberfield extjs 3在 numberfield extjs 3 中为最小值/最大值添加异常
【发布时间】:2019-08-06 14:29:53
【问题描述】:

这样的数字字段

xtype            : 'numberfield',  
fieldLabel       : 'this is a label',
id               : 'id',
name             : 'id', 
width            : 50,
labelStyle       : 'width:300px',
minValue         : 1,
hideTrigger      : true,
allowNegative    : false,
maxValue         : 7,
decimalPrecision : 1,
allowPureDecimal : true,
editable         : true,   
allowBlank       : false

接受数字 1、1.1、3.5 ... 7

但我也需要接受 0。 extjs 中是否存在异常之类的属性或允许输入 0 以及已建立的最小值和最大值的东西?

如果有人可以指导我,我将不胜感激

感谢您的宝贵时间!

【问题讨论】:

  • minValue: 0 不起作用吗?
  • 是的,但我不需要值 0.1 - 0.2 - 0.9 和 minvalue 0 接受该数字

标签: extjs extjs4 extjs3


【解决方案1】:

删除minValuemaxValue 配置,然后使用validator 配置设置自定义验证功能。

    xtype: 'numberfield',
    fieldLabel: 'this is a label',
    id: 'id',
    name: 'id',
    hideTrigger: true,
    allowNegative: false,
    decimalPrecision: 1,
    allowPureDecimal: true,
    editable: true,
    allowBlank: false,
    validator() {
        value = this.getValue();
        if (value === 0 || (value >= 1 && value <=7)) {
            return true;
        }
        return 'Not valid';
    }

【讨论】:

    【解决方案2】:

    我认为没有属性可以做到这一点,但您可以注册一个 change listener 并检查 newValue 参数 是否介于 0 和 1 之间。如果因此,请将 numberfield 的值设置为零。

    listeners: {
        change: function (component, newValue, oldValue) {
            if (newValue > 0 && newValue < 1)
                component.setValue(0);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-23
      • 2018-07-03
      • 2016-03-18
      • 1970-01-01
      • 2020-07-26
      • 2017-05-24
      • 1970-01-01
      相关资源
      最近更新 更多