This is a migrated thread and some comments may be shown as answers.

Multiple values when using Server Filtering

1 Answer 135 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Toby
Top achievements
Rank 1
Toby asked on 29 Jul 2016, 05:19 PM

How do I filter when I have the option for multiple selections using the Separator property

I have a Read action set up which passes the search data through to my controller and I have a client side script set up for the additional data

When a user has selected one user and then starts typing for the second user this pass "Name One; Nam" to the controller.

$("#distributionList").val() is passing the whole string and not the new search for the second name. How can I pass just the text that is being typed in and not the previously selected users.

 

1.function onDistributionListAdditionalData(obj) {
2.                return {
3.                    text: $("#distributionList").val()
4.                };
5.            }

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 02 Aug 2016, 11:05 AM
Hello Toby,

You could split the string by the separator and get the last occurrence either on Client-side: 

function onDistributionListAdditionalData(obj) {
    var autoComplete = $("#distributionList").data("kendoAutoComplete");
    var separator = autoComplete.options.separator;
    var value = autoComplete.value();
    var values = value.split(separator);
    if (values.length == 0) {
        return {
            text: value
        };
    }
    else {
        return {
            text: values[values.length - 1]
        };
    }
}

or Server-side:

function onDistributionListAdditionalData(obj) {
    var autoComplete = $("#distributionList").data("kendoAutoComplete");
    var separator = autoComplete.options.separator;
    var value = autoComplete.value();
    var values = value.split(separator);
    if (values.length == 0) {
        return {
            text: value,
            separator: autoComplete.options.separator
        };
    }
    else {
        return {
            text: values[values.length - 1],
            separator: autoComplete.options.separator
        };
    }
}

public JsonResult GetProducts(string text, string separator)
{  
    text = text.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries).Last();
    . . .
}

Regards,
Peter Milchev
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
AutoComplete
Asked by
Toby
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or