Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs: (TimeField) reset minValue and maxValue

I have an ExtJS TimeField where I use the setMinValue(...) and setMaxValue(...) to only show the valid time-elements to the user. This works just fine, but how do I reset the minValue and maxValue so that the user can see all the time-elements again?

I don't want to clear the field, just show all the elements from the store again.

like image 425
Chau Avatar asked Jan 20 '23 15:01

Chau


2 Answers

I don't see any "clean" way to accomplish this, but I do have a temporary workaround until you find something more suitable.

Try setting the TimeField's minValue and maxValue to undefined or null, and then call generateStore() on your TimeField:

    // private
    generateStore: function(initial){
        var min = this.minValue || new Date(this.initDate).clearTime(),
            max = this.maxValue || new Date(this.initDate).clearTime().add('mi', 
                        (24 * 60) - 1),
            times = [];

        while(min <= max){
            times.push(min.dateFormat(this.format));
            min = min.add('mi', this.increment);
        }
        this.bindStore(times, initial);
    },

Yes it is a private method, so normally you shouldn't use it, but the method would normally be called if you simply reset minValue or maxValue, so you're just skipping a step. By setting both properties to null, the declaration for var min, max = will be equal to the default. You can't go about this by calling setMinValue() or setMaxValue() because it uses a private method that attempts to parse a Date out of the value you pass to the methods (it will fail at parsing null):

    // private
    setLimit: function(value, isMin, initial){
        var d;
        // will fail here
        if(Ext.isString(value)){
            d = this.parseDate(value);
        // will fail as well
        }else if(Ext.isDate(value)){
            d = value;
        }
        // will never make it here, because 'd' wasn't set above
        if(d){
            var val = new Date(this.initDate).clearTime();
            val.setHours(d.getHours(), d.getMinutes(), d.getSeconds(),
                         d.getMilliseconds());
            this[isMin ? 'minValue' : 'maxValue'] = val;
            if(!initial){
                this.generateStore();
            }
        }
    }

Update:

A cleaner approach would be to extend TimeField and add a resetMinAndMax method that accomplishes the above (set minValue/maxValue to null, call to generate store), or add the method in an override. That way you can avoid making calls to the "private" generateStore() everywhere.

like image 120
McStretch Avatar answered Jan 29 '23 22:01

McStretch


you can use simply

this.setMinValue(false);

good luck

like image 33
Dahar Youssef Avatar answered Jan 29 '23 23:01

Dahar Youssef