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

Enter key press in Editable Radcombobox

2 Answers 178 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
saravanan k
Top achievements
Rank 1
saravanan k asked on 16 Jun 2010, 06:22 AM
Hi all,
 
          I am using a radcombobox with allowcustomtext = true intended for adding new values not present in the list. When i click on the combobox it gets opened and by default selection points to the first item. Still I can type a text, but when i  press the "enter key instead of the value i typed it commits the one on which the selection was there. I browsed through the documents and came to know this is the default action on pressing the Enter. But is there any way to avoid this and retain the values typed. Please help.

Regards,
Saravanan K

2 Answers, 1 is accepted

Sort by
0
Accepted
Kalina
Telerik team
answered on 21 Jun 2010, 02:34 PM
Hello saravanan k,

The "Enter" key is used for selecting a RadComboBox item by design.
However you can try to handle the OnClientKeyPressing event and add a new RadComboBoxItem like this:

<script  type="text/javascript">
   
    function AddNewItem()
    {       
        var combo = $find("<%= RadComboBox1.ClientID %>");
        var text = combo.get_text();
        var value = combo.get_value();
        var comboItem = new Telerik.Web.UI.RadComboBoxItem();
        comboItem.set_text(text);
        comboItem.set_value(value);
        combo.trackChanges();
        combo.get_items().add(comboItem);
        comboItem.select();
        combo.commitChanges();
        comboItem.scrollIntoView();
    }
     
    function HandleKeyPress(sender, e) {
  
       if (e.get_domEvent().keyCode == 13) {   
          AddNewItem();
       }
   }
 
</script>


<telerik:RadComboBox ID="RadComboBox1" runat="server"
OnClientKeyPressing="HandleKeyPress"
Height="140px" Width="210px"
CloseDropDownOnBlur="false" AllowCustomText="true" >
<Items>
 <telerik:RadComboBoxItem Text="item 1" Value="1" />
 <telerik:RadComboBoxItem Text="item 2" Value="2" />
</Items>
</telerik:RadComboBox>

Regards,
Kalina
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
saravanan k
Top achievements
Rank 1
answered on 30 Jun 2010, 11:31 AM
Thanks Kalina,

    But i made a slight modification not to add it to the list.

 

function RetainTypedValues() {  
 
var combo = $find("<%= drpdown.ClientID %>");  
 
var text = combo.get_text();  
 
var value = combo.get_value();  
 
combo.clearSelection();  
 
combo.set_text(text);  
 
combo.set_value(value);  
 
combo.commitChanges();  
 
}  
 
function HandleKeyPress(sender, e) {  
 
if (e.get_domEvent().keyCode == 13) {  
 
RetainTypedValues();  
 
}  
 
}  
 

 

 

 

Tags
ComboBox
Asked by
saravanan k
Top achievements
Rank 1
Answers by
Kalina
Telerik team
saravanan k
Top achievements
Rank 1
Share this question
or