1. #1
    Sencha Premium Member
    Join Date
    Jul 2008
    Posts
    17
    Vote Rating
    0
    winter is on a distinguished road

      0  

    Default Unanswered: Listen for ComboBox value changes

    Unanswered: Listen for ComboBox value changes


    When a user selects an item from the combobox list, you could catch that in gxt2 by

    combo.addListener(Events.Select,new Listener <FieldEvent>(){...}


    in gxt3 you can don't seem to have such a method. The combo.addValueChangeHandler only triggers on focus out of the component. Is this expected behaviour? How are you supposed to listen for value changes before the component looses focus?

  2. #2
    Sencha User rohdef's Avatar
    Join Date
    Mar 2010
    Location
    Aarhus, Denmark
    Posts
    67
    Vote Rating
    3
    rohdef is on a distinguished road

      0  

    Default


    I've been looking for something similar for other form elements, such as responding to when a users stops typing in a field. I would argue that the ValueChanged or something similar should fire here, since the value is change whether the user leaves the field or not. Unfortunately I've not found any way to achieve this (admitted, I didn't try that hard).

    Maybe enabling auto validate will solve this?

    Otherwise I think the ComboBox has one advantage in your case, you're most likely able to work around it by listening for collapse events. Although crude and ugly, it should work.

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Vote Rating
    90
    Answers
    109
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    We are planning on adding a SelectEvent to the combobox again. In the meantime, some users have found it possible to use the collapse event to see that the field is closing and to detect changes.

    As for ValueChangedEvent, we plan to use this as it was used in 2.x - only fired when the field is blurred, and then only when the value has changed. The basic reasoning there is that this is how the dom event works when editing an input, and how other GWT fields work as well.

    Keystrokes can be detected on any field with the various key events. A Timer can be used to watch for intervals where the user hasn't made any changes, cancelling and re-scheduling each event. This whole setup could be made into a plugin suitable for any Field, so you can build this functionality in as you need it.

  4. #4
    Sencha User WesleyMoy's Avatar
    Join Date
    Oct 2009
    Location
    Redwood City, California
    Posts
    402
    Vote Rating
    2
    WesleyMoy is on a distinguished road

      0  

    Default


    ComboBox now fires SelectionEvent when an item in the drop down list is selected. This allows you to react to the user choosing an item from the drop down list without waiting for the user to move focus away from the combo box.

    Look for this change in the Release Candidate build.

  5. #5
    Sencha Premium Member
    Join Date
    Aug 2013
    Posts
    7
    Vote Rating
    0
    zoec is on a distinguished road

      0  

    Default ComboBox value changes

    ComboBox value changes


    Hi,

    I've just encountered this issue. Combo boxes are often used to create change in other widgets, such as disabling/enabling appropriately based on selection. A user will expect the value change to be picked up without having to make an additional click.

    I appreciate that we can use the SelectionHandler instead, but this doesn't really solve the problem.

    It might be that you should have a separate Drop down control (which is how we are using it - a user cannot type into our boxes) for this type of scenario which behaves like a DOM SELECT element. If you have one and I missed it, I apologise in advance.

  6. #6
    Sencha Premium Member Neilcoder's Avatar
    Join Date
    Apr 2011
    Location
    Ireland
    Posts
    264
    Vote Rating
    0
    Neilcoder is on a distinguished road

      0  

    Default


    +1

    It would be good if there was some kind of method (unless I've missed it some how) setting the combobox to automtically set the value to cause the value change event to fire (which I'm having problems with manually but if you think that's off topic please ignore for the sake of thread spoiling). e.g. comboboxInstance.setValueChangeOnSelection(true); I beleive there used to be something like this in GXT 2.25

    http://www.sencha.com/forum/showthre...x-issues/page3

  7. #7
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Vote Rating
    90
    Answers
    109
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Try field.setValue(newValue, true) - Field (CellComponent actually) implements HasValue, which has http://www.gwtproject.org/javadoc/la...,%20boolean%29

    Code:
      /**
       * Sets this object's value. Fires
       * {@link com.google.gwt.event.logical.shared.ValueChangeEvent} when
       * fireEvents is true and the new value does not equal the existing value.
       * <p>
       * It is acceptable to fail assertions or throw (documented) unchecked
       * exceptions in response to bad values.
       *
       * @param value the object's new value
       * @param fireEvents fire events if true and value is new
       */
      void setValue(T value, boolean fireEvents);

  8. #8
    Sencha Premium Member Neilcoder's Avatar
    Join Date
    Apr 2011
    Location
    Ireland
    Posts
    264
    Vote Rating
    0
    Neilcoder is on a distinguished road

      0  

    Smile


    Thanks Colin,

    I think I see the problem I was having with setValue() now...

    I was trying to use that before, but without the boolean parameter, the fireEvents defaults to false, so my deduction is that's why I wasn't getting a value change event?

    Code:
      /**
       * Sets this object's value without firing any events. This should be identical to calling setValue(value, false).
       * 
       * It is acceptable to fail assertions or throw (documented) unchecked exceptions in response to bad values.
       * 
       * Widgets must accept null as a valid value. By convention, setting a widget to null clears value, calling getValue()
       * on a cleared widget returns null. Widgets that can not be cleared (e.g. CheckBox) must find another valid meaning
       * for null input.
       * 
       * 
       * @param value the parsed value
       */
      @Override
      public void setValue(T value) {
        setValue(value, false);
      }
    
    I was using setValue(value) before so that might have been what was causing me issues, i think
    Seems to work as expected now.

    Here's an example if anyone should be looking for it;

    PHP Code:
            comboInstance.addSelectionHandler(new SelectionHandler<String>(){

                @
    Override
                
    public void onSelection(SelectionEvent<Stringevent) {
                    
    System.out.println("comboInstance - onSelection" event.getSource().toString()); 
                    
    comboInstance.setValue(event.getSelectedItem(), true);    

                }
                
            });    
            
            
    comboInstance.addValueChangeHandler(new ValueChangeHandler<String>(){

                @
    Override
                
    public void onValueChange(ValueChangeEvent<Stringevent) {
                    
    System.out.println("comboInstance - onValueChange" event.getSource().toString()); 
                    
    //TODO Enter the code or method call here you want carried out on selection
                    
                
    }
                
            });