简体   繁体   中英

KendoUI DropDownList Selects First Item without Interaction

I've got a KendoUI DropDownList, it allows a user to search the server for results and select it from a list. Its an empty list until a search is made.

Currently after a search is made, the first result from the search is selected, even though the user never makes the selection. I'd prefer it to not make any changes unless a user actually makes a selection.

This example works as I would like, but I cannot get it to work the same in my own code. - http://dojo.telerik.com/EjUvu/3

    var control = $(matterControl).kendoDropDownList({
        dataTextField: "DisplayName",
        dataValueField: "ID",
        minLength: 1,
        filter: "contains",
        value:'',
optionLabel: { DisplayName: 'Please enter 1 or more characters', ID: '' }, 
filtering:  function (e)  {
            var filter = e.filter;
            if (filter && !filter.value) { //prevent filtering if the filter does not value 
                e.sender.dataSource.data([]);
                e.sender.text('');
                e.sender.value('');
                e.preventDefault();
             }
         },
        autoBind: false,
        valuePrimitive: true,
        template:
        '<div class="searchResult">'+
        '<span class="searchTitle searchIcon" data-id="#:ID #" >#:DisplayName #</span>' +
                  '<span class="searchDescription">#:Description #</span></div>',
        dataSource: new kendo.data.DataSource({
            serverFiltering: true,
            transport: {
                read: {
                    url: (options) => {
                        var searchValue = options.filter
                            && options.filter.filters
                            && options.filter.filters[0]
                            && options.filter.filters[0].value;

                        var currentId = $(settings.entryIDField).val();
                        var currentText = $(settings.entryNameField).val();

                        if (currentId != null
                            && currentId !== undefined
                            && currentId !== emptyGuid
                            && !searchValue)
                            return defaultRoutes.SearchService.Search + "?searchText=" + currentText + "&recordId=" + currentId;
                        else 
                            return defaultRoutes.SearchService.Search + "?searchText=" + searchValue;
                    },
                }
            },
        }),
        select: function (e: any) {
            var  dataItem  =  this.dataItem(e.item); 
            $(settings.entryNameField).val(dataItem.DisplayName);
            $(settings.entryIDField).val(dataItem.ID);
        }
    });

The behavior you are describing is a limitation, that seems to be addressed already:

https://github.com/telerik/kendo-ui-core/issues/1475

The upcoming 2016 R3 (somewhere in September) will include the fix.

I am not aware of a workaround for the current version that could prevent this from happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM