ComboBox - keyPress problem

I have implemented a comboBox that is populated dynamically via an xml web service.

I type in the first few characters, the drop down populates a large list and I select my option. At this point, if I drop down the list again, there will only be one item in my list, for it fetched a result set with a single item this time, based on the direct match of the text entered.

At this point, if I try to alter the text (backspace, backspace, backspace), I notice that the keyPress events have ceased firing, and my list isn’t populating any more.

I imagine that I need to attack this problem differently, perhaps by setting other properties. Do you have any ideas?

Thanks,
Mark Varvil

<SCRIPT>

    isc.DynamicForm.create({
        fields:[
            {ID:"ComboBoxItem0",
                name:"ComboBoxItem0",
                _constructor:"ComboBoxItem",
                valueField: "Key",
                displayField: "name",
                optionDataSource:  "testDS",
                pickListHeight: 200,
                showPickListOnKeypress:true,
                fetchMissingValues:true,
                filterWithValue:true,
                showOptionsFromDataSource:true,
                keyPress : function() {
                    Log.logWarn("keyPress()");
                }
            }
        ],
        autoDraw:false,
        ID:"DynamicForm0"
    })


    isc.VLayout.create({
        members:[
            DynamicForm0
        ],
        autoDraw:true,
        overflow:"hidden",
        width:"100%",
        ID:"VLayout0",
        height:"100%"
    })


    isc.DataSource.create({
        ID:"testDS",
        dataURL:"/xxx/Partners.do?lookupType=name",
        recordXPath:"/PartnerList/Organization",
        autofetch:true,
        dataFormat:"xml",
        fields:[
            {
                primaryKey:true,
                name:"Key",
                valueXPath:"@OrganizationKey"

            },

            {
                name:"name",
                valueXPath:"@OrganizationName"

            }
        ],
        transformRequest : function (dsRequest) {
            Log.logWarn("transformRequest beginning");
            if (dsRequest.operationType == "fetch") {
                Log.logWarn("transformRequest() fetch beginning");
                Log.logWarn("transformRequest() ComboBoxItem0.getDisplayValue():  " + ComboBoxItem0.getDisplayValue());
                var params = {
                    start : dsRequest.startRow,
                    end : dsRequest.endRow,
                    name: ComboBoxItem0.getDisplayValue()
                };
                return isc.addProperties({}, dsRequest.data, params);
            }
        },
        transformResponse : function (dsResponse, dsRequest, xmlData) {
            Log.logWarn("transformResponse() xmlData:  "   + Log.echoAll(xmlData));
            Log.logWarn("");
            Log.logWarn("transformResponse() dsResponse:  "   + Log.echoAll(dsResponse));
            Log.logWarn("");
            Log.logWarn("transformResponse() dsResponse.data:  "   + Log.echoAll(dsResponse.data));

            dsResponse.totalRows = XMLTools.selectNumber(xmlData,"/PartnerList/@TotalCount");
        }
    });


</SCRIPT>

Hi Mark,

When you have selected a unique option and re-show the pickList, the normal behavior is to show the complete list again.

Can you fill in the details of how you are seeing the behavior you describe: what exact browser, what version of SmartClient, are you using keyboard or mouse navigation and for which steps?

I agree, which makes me think that I have a mismatch of properties set. I am using FireFox 1.5.0.1 and Smart Client 6.0 LGPL.

I type in ‘a’, the list populates from server response with all names beginning with ‘a’.
I make a selection for the unique name ‘abc’.

If I drop click and drop down the list again, SmartClient now sends a request to the server for all names beginning with ‘abc’, which finds 1 row (direct hit).

IF AND ONLY IF, you select this 1 row in the picklist, things begin to go bad, for the keypress event fires, but http requests are no longer sent to the server to populate the list.

IF you don’t select the one item, and instead swipe and type over ‘abc’ and key in ‘xyz’, the http requests will still fire (as expected).

Still not reproducible using Firefox 1.5 and SmartClient 6.0 and your settings.

What’s your SmartClient version?

Are you able to reproduce the problem in the Feature Explorer example that shows a databound comboBox? With the SDK server running on port 8080, the URL would be:

http://localhost:8080/isomorphic/system/reference/SmartClient_Explorer.html#listComboBox

What if you remove your keyPress override (or call Super to ensure restore built-in functionality in not destroyed)

LGPL 6.0 is the code I am using.

I tried removing the keyPress, but this did not make a difference.

I then tried the Feature Explorer, and can NOT reproduce the problem, but it’s not an identical scenario for I am doing a transformRequest and transformResponse.

I believe the root problem may be due to the use of transformRequest (passes in the value typed into the comboBox for a lookup) and/or the transformResponse (where I set the number of rows returned).

After I have selected an item in the listbox, if I click to drop down the list again, an http request is initiated which returns a single row. However, in the Feature Explorer, after selecting an item, and again dropping down the list, I see the expected list of available items, and NOT just the single item available in the list.

What triggers the execution of the http request when I click to drop down the list? After I have selected an item then click to see the list again, It is undesirable for the comboxBox to search again (which results in a direct hit and a single item in my list).

As for the http requests ceasing to fire, perhaps this is due to a cache problem whereas it thinks if there is only 1 row, it doesn’t need to invoke a request???

The code in the initial post “should” replicate this problem, but it requires setup of a server reponse with a variable amount of data returned (based on the comboBox text, start, and end parameters).

A ComboBox’s set of matching items is really a specialized ListGrid under the covers, binding to a DataSource and using a ResultSet identically to how the ListGrid does so.

The discussion of the getPickListFilterCriteria() method is the best single source on how the ComboBox puts together filter criteria that cause either client or server-side filtering.

You will note it mentions comboBoxItem.filterWithValue - this is the property that creates the special cases where a ComboBox with fetch all options even though it has a value that only matches one.

I’ve just noticed you are setting this property, which is read only. Does that correct the problem?

No, unfortunately that did not resolve the problem. I really suspect that the problem (maybe a bug) originates from…, where you follow my scenario, the final fetch happens automatically, and the datasource fetch result then has only one record. At this point, there is no cache, and the paging mechanism seems is not correct. For at this point in the scenario, the keystrokes don’t force a fetch of data.

I wish I had an external location to put some server side code to demonstrate this for you. I imagine this would work fine if I were pulling all the data and filtering it locally, but I’m trying use a comboBox to allow the type-ahead selection of 1 of 20,000 names in the database.

I KNOW SmartClient can do this…I just haven’t found the right combination of code yet.

Thanks,
Mark

Sorry, I just noticed something you said - in transformRequest you actually grab the value directly from the comboBox? If so, that’s your problem. As previously indicated, when the drop-down list of options is show via explicitly clicking on the drop-down button, SmartClient omits the typed in value from the filter criteria. This is the sole reason why a list of all options is shown. This is all covered in the docs for getPickListFilterCriteria.

If you are explicitly re-introducing the typed-in value, that explains this behavior exactly. If you are forcing all DataSource fetches to use the typed-in value, there is no way for SmartClient to get back to the full list.

Make sense?

So…yes…we are using the value typed in (a partial name) to query the database via transformRequest, along with start and end parameters. With your latest response, we are perplexed; so let me try to explain the use case and perhaps you can recommend another approach for us to try.

On a search criteria entry form, we need a user to select a “name” from a list of 20,000 names in a database table. As the user types characters into the comboBox, we want to query the database and return the names that begin with the entered string. The implementation would be similar to the Google toolbar search functionality, where its suggests names as you type.

This is the functionality demonstrated in the feature explorer, but that example doesn’t use transformRequest to pass in the comboBox’s displayValue, or transformResponse to set the dsResponse.totalRows.

As previously mentioned, we have “almost” implemented this successfully with the SmartClient comboBox control, with the exception mentioned in this thread.

I hope this makes sense; and hopefully you can steer us in the right direction.

Thanks for you help,
Mark Varvil

Hi Mark,

When the ComboBox initiates a request to the server it already includes the value typed in by the user if and only if the ComboBox is trying to fetch a filtered set of values. By adding the typed-in value unconditionally, you remove the ability for the ComboBox to fetch the full set of values, which is what it is trying to do when you click on the PickList and a value is typed in.

You don’t need to add the typed-in value transformRequest() - when the ComboBox is making a request where filtered results are desired, you will find the typed-in value in dsRequest.data by the time transformRequest is called. Just make sure the value as passed to you in dsRequest.data makes it to the server in the same way that you currently pass the value from the ComboBox.

Success!

I was able to get this to work, and wanted to post the final code to share with others.

The source of my problem was my setting of the comboxBox’s display value in transformRequest. I needed to let SmartClient do this for me automatically.

It is also worth mentioning, that you MUST use selectNumber as opposed to selectString appropriately; See transformResponse():

dsResponse.totalRows = XMLTools.selectNumber(xmlData,"/TraderList/@TotalCount");

Thanks for all the help,
Mark Varvil

Full Example:

<SCRIPT>
    isc.DynamicForm.create({
        fields:[
            {ID:"ComboBoxItem0",
                name:"ComboBoxItem0",
                editorType:  "comboBox",
                valueField: "Key",
                displayField: "name",
                optionDataSource:  "testDS",
                pickListHeight: 200,
                fetchMissingValues:true,
                showOptionsFromDataSource:true
            }
        ],
        autoDraw:true,
        ID:"DynamicForm0"
    })

    isc.VLayout.create({
        members:[
            DynamicForm0
        ],
        autoDraw:true,
        overflow:"hidden",
        width:"100%",
        ID:"VLayout0",
        height:"100%"
    })

    isc.DataSource.create({
        ID:"testDS",
        dataURL:"/XXX/Traders.do?lookupType=name",
        recordXPath:"/TraderList/Organization",
        autofetch:true,
        dataFormat:"xml",
        fields:[
            {
                primaryKey:true,
                name:"Key",
                valueXPath:"@OrganizationKey"
            },
            {
                name:"name",
                valueXPath:"@OrganizationName"
            }
        ],
        transformRequest : function (dsRequest) {
            if (dsRequest.operationType == "fetch") {
                var params = {
                    start : dsRequest.startRow,
                    end : dsRequest.endRow
                };
                return isc.addProperties({}, dsRequest.data, params);
            }
        },
        transformResponse : function (dsResponse, dsRequest, xmlData) {
            dsResponse.totalRows = XMLTools.selectNumber(xmlData,"/TraderList/@TotalCount");
        }
    });
</SCRIPT>

Hi Mark,

Glad to hear this worked out, and thanks for showing the final code.

That issue with totalRows is an easily eliminated gotcha, we’ll get rid of that.

The issue with totalRows has been fixed for SmartClient 6.1.