Announcement

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

    ComboBoxItem Value Reset on Focus Lost

    Library Version:
    SmartGWT 2.4
    GWT 2.1.1
    Firefox 3.6.8

    Hi,

    I am having an issue with ComboBoxItem where the value which is selected from the drop down list is reset to the defaultValue as soon as any other component is clicked on any other form or panel.

    I have added event handlers to it to see if it is ever receiving the change event and noticed that some handlers are never called.. I have tested the following:
    ChangeHandler - never called
    ChangedHandler - never called
    FocusHandler - called
    ClickHandler - called

    I assume the fact that it is not receiving events has something todo with it resetting..

    The code to create the ComboBoxItem is as follows:

    Code:
    LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
    values.put("Low", "Low");
    values.put("Medium", "Medium");
    values.put("High", "High");
    
    ComboBoxItem item = createComboBoxItem("Test", "Low", values);
    
    
    DynamicForm form = new DynamicForm();
    form.setNumCols(2);
    form.setWidth100();
    form.setTitleWidth("*");
    form.setFields(item);
    
    
    ....
    
    
    public static ComboBoxItem createComboBoxItem(String title, String   defaultItem, LinkedHashMap<String, String> values) {
            ComboBoxItem item  = new ComboBoxItem();
            item.setTitle(title);
            item.setTitleAlign(Alignment.LEFT);
            item.setWidth(95);
            item.setAddUnknownValues(false);
      
            item.setValueMap(values);
            item.setDefaultValue(defaultItem);
    
            return item;
        }

    this is then added to a forum and then to a DynamicForm which in turn is added to a HLayout.. There are many different ComboBoxItems in the application but all of them are located on different Form's.. I don't know if this matters or not but i'm trying to give as much info as possible..


    I am using firefox 3.6.8 and have also tested in Chrome (i know there is an issue with ComboBoxItem in Chrome even with the latest GWT update where google were supposed to have it fixed in 2.1 -- i have commented here about this http://code.google.com/p/smartgwt/issues/detail?id=386 )..

    There are no errors or warnings whatsoever produced in any console...

    Any help is greatly appreciated..

    Thanks,

    #2
    The documentation for setAddUnknownValues () says:
    Code:
    public void setAddUnknownValues(Boolean addUnknownValues)
    If set to false, if a value has been entered that does not match an entry in the ValueMap or a value loaded from the optionDataSource, it will be discarded if the user leaves the field.
    When this mode is enabled, getValue will return null unless the value typed in by the user has valid matches. Use ComboBoxItem.getEnteredValue to get the raw value typed in by the user.
    
    Note that this flag effectively enables completeOnTab, since leaving the field in general (whether by tab or another means) will attempt completion, and discard the value if no valid completion exists. As with completeOnTab, if the typed in value has more than one match, the first match will be used.
    
    Parameters:
    addUnknownValues - addUnknownValues Default value is true
    So it looks like you want to leave it "true".
    Then you can call getEnteredValue () to get the value entered by the user.
    Though I am not sure how you tell it apart from a "picked" value... you may have to compare the value returned via getEnteredValue () to each value you added to the combo-box to make sure it is indeed a value that's not already in the box...

    Comment


      #3
      Hi Thanks for the quick response,


      Code:
      If set to false, if a value has been entered that does not match an entry in the ValueMap or a value loaded from the optionDataSource, it will be discarded if the user leaves the field.
      When this mode is enabled, getValue will return null unless the value typed in by the user has valid matches. Use ComboBoxItem.getEnteredValue to get the raw value typed in by the user.
      This line from the docs lead me to believe that this would only ignore values which a user tried to type in which were not in the ValueMap (say they typed ("Highest" instead of "High").. This is the functionality i want.

      However if the user clicked on "High" from the Dropdown list (or type it) - as "High" is in the dropdown selection and contained in the ValueMap it should not be ignored and the selection should not default back..? This is not what was happening!

      Are you sure this is the intended functionality? This conflicts with what is stated in the first line of the documentation - I do want to ignore any value which has been entered that does not match an entry in the ValueMap when the user leaves the field. However I do not want to ignore a value selected from the dropdown selection. Therefore should i not set the value to false? What does setting it to false achieve?

      Maybe I am completely misreading the docs and i'm sorry if i am but i have read over this multiple times to see if it make sense to have the problem i described with that option set to false and I just cant make sense of it..


      Thanks,

      Comment


        #4
        Yeah... that does not make sense to me.
        I would stick this in a stand-alone case, and see if Isomorphic can explain on the forum, or if it clearly does not work as documented, open an issue here:
        http://code.google.com/p/smartgwt/issues/list.

        Comment


          #5
          Thank you very much.. Will do.

          Comment


            #6
            Hello,

            any news on this?

            I'm experiencing the problem that when using setAddUnknownValues(false), no change or changed handlers get called - ever. I think this is the same problem you are having. I also tried experimenting with setChangeOnKeypress(false), but this disables the automatic suggestion of options while typing.

            Comment


              #7
              Hi Sorry,

              I set setAddUnknownValues (true) instead of false and it works.. The only hitch is having to check after getValue() that it was in the original list of options..


              I have not submitted a bug request yet - have not had the time to.

              Comment


                #8
                We need a standalone test case.

                Comment


                  #9
                  When using setAddUnknownValues(false) on a ComboBoxItem, which does what I need, ChangedHandler and ChangeHandler doesn't fire. Ever. It's as simple as that.

                  Comment


                    #10
                    I agree but if it will help get it fixed quicker - here it is

                    Code:
                    public class ComboBoxBugExample implements EntryPoint {  
                      
                        public void onModuleLoad() {  
                      
                            LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
                            values.put("Low", "Low");
                            values.put("Medium", "Medium");
                            values.put("High", "High");
                    
                            ComboBoxItem item = createComboBoxItem("Test", "Low", values);
                    
                    
                            final DynamicForm form = new DynamicForm();  
                            form.setWidth(250);  
                            form.setNumCols(2);
                            form.setWidth100();
                            form.setTitleWidth("*");
                            form.setFields(item);
                      
                            form.draw();  
                        }  
                    
                    
                        public static ComboBoxItem createComboBoxItem(String title, String   defaultItem, LinkedHashMap<String, String> values) {
                            ComboBoxItem item  = new ComboBoxItem();
                            item.setTitle(title);
                            item.setTitleAlign(Alignment.LEFT);
                            item.setWidth(95);
                            item.setAddUnknownValues(false);
                      
                            item.setValueMap(values);
                            item.setDefaultValue(defaultItem);
                    
                            return item;
                        }
                      
                    }

                    Comment


                      #11
                      @plech.d If it's easily reproduced then creating a standalone test case should likewise be very easy.

                      willfluery, what is your test case intended to demonstrate? There don't seem to be any change handlers. If it's supposed to demonstrate some other problem can you spell out the expected and observed behaviors and the clicks and keystrokes needed to repro the problem?

                      Comment


                        #12
                        The test case is intended to show that the Widget does not function as intended.

                        The problem is when you select either "Medium" or "High" using either the drop down list or by the autocomplete feature - when the ComboBoxItem loses focus it resets the selection to "Low" i.e. the default selection.

                        if you comment out
                        Code:
                        item.setAddUnknownValues(false);
                        then it will keep the correct selection but the user is allowed to enter invalid items..

                        I had added the code for the change handler while testing simply to try and track down the cause of the bug myself.

                        Comment


                          #13
                          We aren't reproducing this issue.
                          We tested against Firefox and IE, against the (Evaluation enterprise edition) nightly build dated Feb 23.

                          In our tests
                          - clicking on the icon to show the pick list
                          - selecting "Medium" or "High"
                          - hitting Tab, or clicking in the URL bar to take focus from the item
                          didn't result in the value being dropped and if we modified the sample to add a "changed" handler it correctly fired.

                          Can you verify that you're still seeing this issue against the latest nightly build and if so confirm what browser / platform you're seeing the bug on, what version of gwt you're running against and exactly the sequence of events that causes it to manifest.

                          Regards
                          Isomorphic Software

                          Comment


                            #14
                            Hi Sorry for not replying earlier.

                            The version i am using is the latest one available at

                            http://code.google.com/p/smartgwt/downloads/list

                            I did not try to build against the night versions as they usually contain other bugs due to work in progress..

                            I acknowledge though that i should have tested it against the latest version available on this site - not through the google code site..

                            Comment


                              #15
                              Hi Will,
                              Thanks for the update. Since we're not reproducing this against the latest code it's likely the issue has been fixed.

                              If you do see the issue against the latest nightly available from http://smartclient.com/builds, please let us know.

                              Comment

                              Working...
                              X