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

Only allow RadSearchBox selection to be one of the listed options

2 Answers 85 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 23 Aug 2018, 08:00 PM

I have a RadSearchBox.  The user can start typing and a list of selections comes up.

Is there a way I can restrict the user from typing in invalid choices?  I want to force them to choose one of the items on the list.

Any ideas on the best way to approach this would be appreciated!

2 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 14 Sep 2018, 07:43 AM
Hello Adam,

We have created a KB article that covers this scenario - Ensures an item is selected when searching with SearchBox

<telerik:RadSearchBox HighlightFirstMatch="true"  OnClientLoad="OnClientLoad" ... >
</telerik:RadSearchBox>

<script>
    function OnClientLoad(sender, args) {
        // clear the text if there is no selected item
        if (!sender._highlightedItem) {
            sender.get_inputElement().value = "";
        }
    }
    function OnClientSearch(sender, args) {
        // prevent postback if no item is selected
        if (!sender._highlightedItem) {
            sender._postBackOnSearch = false
        } else {
            sender._postBackOnSearch = true
        }
    }
</script>

Regards,
Peter Milchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Adam
Top achievements
Rank 1
answered on 14 Sep 2018, 04:05 PM
Fantastic.  Thank you!
Tags
SearchBox
Asked by
Adam
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Adam
Top achievements
Rank 1
Share this question
or