Extjs: (TimeField) reset minValue and maxValue

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

I do not want to clear the field, just show all the items from the store.

+4
source share
4 answers

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

Try setting the TimeField 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, this is a private method, so usually you should not use it, but the method is usually called if you just reset minValue or maxValue, so you just skip the step. By setting both properties to null, the declaration for var min, max = will be the default value. You cannot get around this by calling setMinValue() or setMaxValue() , because it uses a private method that tries to parse the date from the value you pass to the methods (it will not work when parsing zero):

  // 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 the TimeField and add a resetMinAndMax method that does the above (set minValue / maxValue to null, invoke the creation of the repository) or add a method to the override. This way you can avoid calls to "private" generateStore() everywhere.

+5
source

you can just use

 this.setMinValue(false); 

luck

+3
source

Only extjs reset the property "value" from the component (if I'm not mistaken), well, I donโ€™t know if my code is better, but ... as above, I override the reset method from the DateField class using the code of the Field class and add more 2 properties to keep the original values โ€‹โ€‹(originalMinValue and originalMaxValue).

the original value MinValue and originalMaxValue are fired in the Render event of my date field.

 this.setValue = this.setValue.createSequence(this.updateHidden); this.originalMinValue = this.minValue; this.originalMaxValue = this.maxValue; // this is part of me onRender event code 

and that redefinition

 Ext.override(Ext.form.DateField,{ originalMinValue : null, originalMaxValue : null, reset : function() { this.setValue(this.originalValue); this.setMinValue(this.originalMinValue); this.setMaxValue(this.originalMaxValue); this.clearInvalid(); } 

})

Thus, we can use the reset method of component e, then the value, minValue and MaxValue, returning to the original value.

Sorry for my bad english.

+1
source

Are you after the initial values โ€‹โ€‹for the time field when loading the page? In this case, you should use the reset () method of the FIELD class. You must have access to this as the time field component extends from FIELD.

0
source

Source: https://habr.com/ru/post/1337273/


All Articles