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

is there a click dropdown event?

4 Answers 162 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
John Hadjioannou
Top achievements
Rank 1
John Hadjioannou asked on 12 Aug 2010, 01:26 PM
I would like to clear the text of the combobox when the user presses the button to open the dropdown, but not when it opens of its own accord.  Is there a click event for the button that I can use, or some other way of achieving this?

John

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Aug 2010, 11:59 AM
Hello John,

I guess you want to open the RadComboBox and clear its text in an external button click. If so try the following code snippet.

ASPX:
<telerik:RadComboBox ID="RadComboBox2" runat="server" Text="select" AllowCustomText="true">
    <Items>
       <telerik:RadComboBoxItem Text="aaa" />
       <telerik:RadComboBoxItem Text="bbb" />
    </Items>
 </telerik:RadComboBox>
        
 <asp:Button ID="Button4" runat="server" Text="Open" OnClientClick="return clearText();"  />

Java Script:
<script type="text/javascript">
   function clearText() {
      var combo = $find("<%=RadComboBox2.ClientID %>");
      combo.clearSelection();
      combo.showDropDown(true);
      return false;
    }
</script>

Thanks,
Princy.
0
John Hadjioannou
Top achievements
Rank 1
answered on 17 Aug 2010, 08:30 PM
Hi Princy

Thank you for the suggestion.

My situation is a little different.

I would like the text to clear when the user clicks on the button that is part of the combobox to open the dropdown.

The rationale is this:  If an item is already selected the only item that will show in the dropdown initially is the selected item, meaning that the user will have to clear the text manually to see the other choices.  If the user is opening the dropdown it is because they want to change the selected item - clearing the text for them saves them a step.

I suppose what I am looking for is a weay of finding the Id of the combobox's button so I can attach an on-click event to it.

Any ideas?

Thanks
John
0
Accepted
Simon
Telerik team
answered on 18 Aug 2010, 10:32 AM
Hi John Hadjioannou,

You can handle the DropDownOpening event and verify whether the event has been risen by the Image Button of the RadComboBox and then clear the text or execute some other logic, e.g.
function onDropDownOpening(sender, eventArgs) {
    if (eventArgs.get_domEvent().target == sender.get_imageDomElement())
        sender.set_text("");
}

I hope this helps.

Kind regards,
Simon
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
John Hadjioannou
Top achievements
Rank 1
answered on 18 Aug 2010, 11:29 PM
Thanks, Simon

I had to add a check:

eventArgs.get_domEvent() != null


but apart from that it did the trick.

John
Tags
ComboBox
Asked by
John Hadjioannou
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
John Hadjioannou
Top achievements
Rank 1
Simon
Telerik team
Share this question
or