Announcement

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

    disallow custom values in ComboBoxItem

    Currently we use a SelectItem where the user can pick from a predefined list (filled with setValueMap). The list to pick from is growing rapidly, so I want to change to a ComboBoxItem, allowing the user to type the first few charaters to filter the list. The user should however not be allowed to leave a value that is not in the predefined list. In my experience I never have to program anything like that on SmartGWT widgets because almost all functionality you can think of is pre-programmed. So I started looking for a method like setAllowCustomValues or something, but could not find one that I think I can use.

    I also investigated the isOneOf validator, but the problem there is that I do not want to use the validateOnChange because I want the user to be able to enter some characters, not validate on every new character, and on this specific form (part of a wizard), the item is the only one so I cannot use validateOnExit (user cannot exit the widget ;) ).

    Am I using the right widget to accomplish the described behaviour, and if so, how would you recommend to get the desired behaviour?

    thanks,
    Iwan

    #2
    So question, say the user types "Fred" and no Fred exists in the valuemap, and the user tries to move away from the combobox, what is the expected behavior? Does it revert back to the last selected item? Does the combobox retain focus? Does an error appear?

    Comment


      #3
      any of those will do, but revert to the previous valid option would be best.

      Comment


        #4
        Well technically the easiest way would be to add the IsOneOfValidator and then add your own blur handler. If the form validates, good, otherwise perform whatever logic to handle the invalid value (form.validate()) will show the error by default unless you do form.clearErrors(true) at the end of the handler. The only "unclean" part is to revert to the last value you would need to track that value.

        Comment


          #5
          I have the same issue/requirement as itb. I don't think using an isOneOfValidator is necessarily a good solution - in order for the isOneOfValidator to work; you need to pass it a String[] array of allowed values.
          While that is of course trivial from a technical standpoint; the problem lies in the fact that typically, you want to use a ComboBoxItem when you're dealing with large resultsets to give users the search-and-autocomplete feature. That's precisely what itb described.

          Well, if you're dealing with such a large result-set, you don't want to load the entire resultset just to be able to give the validator a list of allowed values. That's very expensive and introduces a noticeable slowdown in the application. In my application; I have a screen with 4 comboBoxItems; each of which can potentially display tens of thousands of options. I did a lot of work on the Datasource side to ensure that the comboBoxes are only loading small pieces of this list so that users aren't confronted with a "Contacting Server" message that lasts several seconds.

          It seems kind of silly that I'd have to do this after all - with the negative side-experience for the user as a side-effect - just to ensure the user doesn't enter a random value and blow up my DMI+Hibernate stack in the backend.

          A customValidator might be a better option; but again, that's a lot of work; especially considering that, at some level, the comboBoxItem already "knows" whether or not the typed in value matches an entry from the optionDataSource. What I mean is this: if my optionDataSource returns users like this:

          ID: 1 Name: John
          ID: 2 Name: Jane

          the comboBoxItem will return a value of "1" when I type "John" but "Jess" when I type "Jess". So obviously it knows when a value is matched. It would be nice if the comboBoxItem exposed this through a getter; i.e. Boolean getValueMatch() or something along those lines.

          Comment


            #6
            I suppose a potential workaround would be a data arrived handler to the combobox, then you can set your own flag based on whether anything returned.

            Comment


              #7
              Originally posted by svjard
              I suppose a potential workaround would be a data arrived handler to the combobox, then you can set your own flag based on whether anything returned.
              That is an excellent idea, hadn't thought of that. Sub-class comboBox to add a getValueMatch() property, add a dataArrivedHandler and based on what comes back return true or false in the getValueMatch().

              Excellent idea Svjard, thanks!

              Comment

              Working...
              X