Announcement

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

    Require min chars in ComboBoxItem with DS and pick list

    We'd like to have a proper suggest item widget. The closest we came to is using a ComboBoxItem withouth pick list icon that completes on tab. This widget is attached to a data source.

    However, since the value map i.e. the pick list is potentially really large we require the user to enter a number of chars before suggesting values. The following code ensures that the pick list is only displayed after the minimum number of required characters was entered.

    Code:
    addChangedHandler(new ChangedHandler() {
    
      @Override
      public void onChanged(ChangedEvent event) {
        if (getValueAsString() != null) {
          setShowPickListOnKeypress(getValueAsString().length() >= minChars);
        }
      }
    });
    BUT this has no impact on the requests that are being issued against the data source. Hence, if 'minChars' is 3 there are still DS requests against the server even if only a single char was entered.

    Is there a way to suppress this?
    Last edited by fhisg; 7 Mar 2013, 08:41.

    #2
    In 4.0d there is now just a simple flag you can set: comboBoxItem.minimumSearchLength.

    In previous versions you would need take a more complicated approach of using transformRequest/transformResponse to avoid going to the server if the search string was too short, returning a zero records, and then setting a special flag so that you can dynamically change the emptyMessage on the PickList to say something like "Type at least X characters to search".

    Comment


      #3
      Oh, nice. Something to look forward to in 4.0.

      Overriding transformResponse to return zero records is clear and straightforward. However, what would one do in transformRequest? There would have to be some sort of "abort/cancel/stop-right-here" method on the DSRequest for that, no?

      Comment


        #4
        Right. By using a clientCustom DataSource you can just programmatically put together your DSResponse and provide it via processResponse(). So this can be approached as a facade over another DataSource - requests with a long enough search string are passed on to the real DataSource, others get an immediate response.

        Obviously, not as easy as setting a flag, so defer this until you can migrate to 4.0 if you have that option.

        Comment

        Working...
        X