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

Won't AutoCompleteBox fire JS events?

2 Answers 74 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Yan Moura asked on 23 Jun 2020, 07:13 PM

I would like to implement a feature that depends on what user types in -- so I need to constantly check the contents of the input box. The obvious way of doing it is by running a JS function invoked by the onkeyup (or onkeypress, etc) but AutoCompleteBox is not firing the event.

A snippet of my code:

<script>
function ChangeTest() {
   console.log('changed');
}
</script>
 
<telerik:RadAutoCompleteBox RenderMode="Lightweight" runat="server" ID="RadAutoCompleteBox1"
            autopostback="true"
            DataSourceID="SqlDataSource1" DataTextField="field1" DataValueField="field2" InputType="Token" Width="100%"
            DropDownWidth="150px"
            OnEntryAdded="RadAutoCompleteBox1_EntryAdded"
            OnEntryRemoved="RadAutoCompleteBox1_EntryRemoved"
            OnClientEntryAdded="CheckEntry"
            OnClientEntryRemoved="CheckEntry"
            onkeyup="ChangeTest"
>

 

What am I doing wrong?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 23 Jun 2020, 08:08 PM

Hi there,

You can see how to attach to the keypress event of the autocomplete input in this KB article: https://www.telerik.com/support/kb/aspnet-ajax/autocompletebox/details/allow-to-select-only-one-text-item-or-a-single-token-item-in-radautocompletebox, e.g.

<script>
    function OnClientLoad(sender, args) {
        $telerik.$(sender.get_inputElement()).on('keypress', function (e) {
            ...
        });
    }
</script>
<telerik:RadAutoCompleteBox runat="server" Width="250px" EmptyMessage="Choose a single text item..."
    InputType="text" TextSettings-SelectionMode="Single" ID="RadAutoCompleteBox1" OnClientLoad="OnClientLoad">
</telerik:RadAutoCompleteBox>

 

Regards,
Rumen
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Yan Moura
Top achievements
Rank 1
Veteran
Iron
answered on 25 Jun 2020, 02:46 PM
Thank you, Rumen. It did the trick!
Tags
AutoCompleteBox
Asked by
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Answers by
Rumen
Telerik team
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Share this question
or