Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    CheckboxItem and ChangedHandler

    Hi.
    I'm facing problem with executing onChanged handler while onChange handler cancels event,
    is it normal behavior, or maybe it's a bug ??

    here's an example:
    Code:
    DynamicForm form = new DynamicForm();
    CheckboxItem checkbox = new CheckboxItem("test", "My CheckBox");
    checkbox.addChangeHandler(new ChangeHandler() {
    	@Override
    	public void onChange(ChangeEvent event) {
    		event.cancel();
    	}
    });
    checkbox.addChangedHandler(new ChangedHandler() {
    	@Override
    	public void onChanged(ChangedEvent event) {
    		SC.say("Why is this fired ?");
    	}
    });
    form.setFields(checkbox);
    tested on:
    SmartClient Version: v8.3_2012-11-20/LGPL Development Only (built 2012-11-20)

    FF 16.0.1
    Chrome 27,0,1453,116 m

    #2
    Change(d)Event semantics

    I have the same problem, but here's what I found (all empirical observations):

    * Checkbox state is unchecked
    * User checks it
    * onChange called (remember, because we're checking it):
    event.getItem().getValue() == event.getOldValue() == false
    event.getValue() == true
    * onChange cancels
    * ChangeEvent.isCancelled is called and then onChanged is called, but
    event.getItem().getValue() == event.getValue() == false!!!

    Same for the reverse.

    So the semantics of Change(d)Event is the following:
    ChangeEvent is fired on change, ChangedEvent is fired after ChangeEvent (always)
    if ChangeEvent is cancelled, ChangedEvent.getValue() == ChangeEvent.getOldValue()
    if ChangeEvent is intact, ChangedEvent.getValue() == ChangeEvent.getValue()

    Can't say anything about multiple Change(d)Handlers right now.

    Comment

    Working...
    X