setValue of SmartSelect without triggering "change"

Hi,

SmartSelect’s setValue() and unsetValue() includes trigger of “change”.

I think some (or most) of the time people don’t want the “change” handler to be run when we do setValue().
One of my case is, setValue() to initial value and don’t want “change” to trigger my autosave().
Another case is, in ‘change’ handler I may do unsetValue() base on some logic. This causes loop.

I suggest newer Framework7 to take this into account. thanks.

I have workarounds for this problem.

Framework7.SmartSelect.prototype.setValueWithoutEvent = function(value){
	const ss = this;

	let trigger0 = ss.$selectEl.trigger;
	ss.$selectEl.trigger = ()=>{};

	ss.setValue(value);

	ss.$selectEl.trigger = trigger0;
	
	return ss;
};

or

Framework7.SmartSelect.prototype.setValue0 = Framework7.SmartSelect.prototype.setValue;
Framework7.SmartSelect.prototype.setValue = function(value, fireEvent=false){
	const ss = this;

	if( fireEvent ){
		ss.setValue0(value);
	}else{
		let trigger0 = ss.$selectEl.trigger;
		ss.$selectEl.trigger = ()=>{};
	
		ss.setValue0(value);

		ss.$selectEl.trigger = trigger0;
	}
	
	return ss;
};
1 Like