0

Events in Comboitems inherits from Combobox?

asked 2012-01-23 10:22:31 +0800

DaniG gravatar image DaniG
78 1

Hi... (sorry about my poor english)

I am using ZK 5.0.9

I have a zul page but I am putting almost all the properties of each component in my GenericForwardComposer.

I have a Combobox with some Comboitems. I have a problem because the Combobox has to make an action when it receive the focus (with the ONFOCUS event), but I have seen it fire the event with every change of selection. It seem as if all the Comboitems (which has not events declared) has got the event from the parent. My question is... am I wrong? and if not, How can I prevent it?.

Thanks to all

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-01-23 12:37:15 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi DaniG,

It will fire event if you listen it, for example,

<combobox onOpen="" onChange="" ...

You can prevent it by unlisten event.

Regards,
ben

link publish delete flag offensive edit

answered 2012-01-24 13:01:24 +0800

DaniG gravatar image DaniG
78 1

Hi ben...

Thanks for your time. Sorry, I am not sure to understand you. Maybe I am doing something wrong.

My zul is quite simple:

<combobox id="T1_DOM_CODPROVINCIA" />

My GenericForwardComposer is more or less like:

comboProvincia = (Combobox) ventana.getFellow("T1_DOM_CODPROVINCIA");
comboProvincia.addEventListener(Events.ON_FOCUS, new SerializableEventListener() {
        @Override
        public void onEvent(Event event) throws Exception {
            guardaValor();
        }
});
comboProvincia.addEventListener(Events.ON_BLUR, new SerializableEventListener() {
        @Override
        public void onEvent(Event event) throws Exception {
            compruebaComponente();
        }
});

cargaComboProvincias(); //call to the method which loads the Combo

...

//Method to load the Combo
public void cargaComboProvincias()
{
        List<TipoDatosCampoValor> listado;
        try
        {
                listado = clienteM.getClientGestorModelo().getTablaDatosAuxiliares("PROVINCIAS");
       
                for(TipoDatosCampoValor tipoDatosCampoValor : listado)
                {
                        comboitemProvincia = new Comboitem();
                        comboitemProvincia.setLabel(tipoDatosCampoValor.getValor());
                        comboitemProvincia.setValue(tipoDatosCampoValor.getNombreCampo());
                        comboProvincia.appendChild(comboitemProvincia);
                }
        }
        catch (MtrrException mtre) {
        }
}

Then... I don't know why (WITHOUT TO EXIT OF THE COMBOBOX) every time I click on an option all Comboitems fire the event ON_FOCUS, so calls the method guardaValor() (which only when Combobox receive focus have to be fired), and I don't know how to prevent it.

Any idea?

Regards

link publish delete flag offensive edit

answered 2012-01-24 14:18:38 +0800

RichardL gravatar image RichardL
768 4

You could use removeEventListener or have an if statement to see if a condition has been met before calling guardaValor().

link publish delete flag offensive edit

answered 2012-01-24 17:29:27 +0800

DaniG gravatar image DaniG
78 1

Hi RichardL,

Yes, as you say I can put a flag or use a condition to know when the Combobox fire the event and when the Comboitems are (better than to remove my listener, because users need it lot of times). Thank you very much. Just I was asking myself... why I need it?. I mean, why the Comboitems fire a method with an event I didn`t write on its?. Are they taking it from parent?... why?...

link publish delete flag offensive edit

answered 2012-01-25 03:38:44 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

It's the default action of Comboitem/Combobox,
Combobox will get focus and select the previous value so user can type a new value easily.

You can add the fragment below into your zul page to prevent it:

<script type="text/javascript">
	zk.afterLoad("zul.inp", function () {
		zul.inp.Comboitem.prototype.doClick_ = function (evt) {
			if (!this._disabled) {
				this._doMouseOut();
	
				var cb = this.parent;
				cb._select(this, {sendOnSelect:true, sendOnChange: true});
				this._updateHoverImage();
				cb.close({sendOnOpen:true});
				
				// Fixed the onFocus event is triggered too late in IE.
				cb._shallClose = true;
				evt.stop();
			}
		}
		zul.inp.Combobox.prototype._select = function (sel, opts) {
			var inp = this.getInputNode(),
				val = inp.value = sel ? sel.getLabel(): '';
			this.valueSel_ = val;
		}
	});
</script>

You may want write it once in zk.xml for all page,
please refer to zk.xml/The device-config Element/The embed Element

Best Regards,
ben

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-01-23 10:22:31 +0800

Seen: 193 times

Last updated: Jan 25 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More