Blame view

js/app/views/StandardFloatField.js 1.08 KB
5fdc383e   Erdogan Furkan   #11199-Done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Ext.define('amdaUI.StandardFloatField', {
    extend: 'Ext.form.field.Text',

    xtype: 'standardfloatfield',

    // Additional configurations and custom logic can be added here
    regex: /[-+]?(?:\d*\.?\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/,
    min:-Number.MAX_VALUE,
    max: Number.MAX_VALUE,

    initComponent: function () {
        this.callParent();

        // Set up validation and change event handling
        this.validator = this.createValidator();
    },

    createValidator: function () {
        var me = this;

        return function (val) {
            var errMsg = null;
            if (!me.allowBlank && Ext.isEmpty(val)) {
                errMsg = 'Blank value not allowed';
            } else if ((typeof me.min !== 'undefined' && me.min !== null) && (parseFloat(val) < me.min)) {
                errMsg = 'Min. allowed value is ' + me.min;
            } else if ((typeof me.max !== 'undefined' && me.max !== null) && (parseFloat(val) > me.max)) {
                errMsg = 'Max. allowed value is ' + me.max;
            }

            return errMsg ? errMsg : true;
        };
    },
});