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

RadComboBox OnClientKeyPressing

3 Answers 165 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Shan
Top achievements
Rank 1
Shan asked on 03 Aug 2012, 02:36 PM
I am trying to restrict users entering Regular Expression value like  <%^>/   in RadComboBox while typing  but it throws error message "Object doesn't support this property or method" 

I want to validate it while typing in RadComboBox.

function OnClientKeyPressing(sender, args) {
if(checkRegEx())      // checking the RegEx value, if pass then proceed else remove the last character entered  
                    {
// Proceed.......
}
else
{
args.set_cancel(true);  // ERROR : Object doesn't support this property or method 

}                
            }




<telerik:RadComboBox ID="rcbMonthEndDate" Runat="server" TabIndex="5"
DropDownWidth="100px" MarkFirstMatch="true" AllowCustomText="true" EnableLoadOnDemand="false"
   HighlightTemplatedItems="true" OnClientKeyPressing="OnClientKeyPressing" 
   NoWrap="true" EmptyMessage="Select Date" AutoPostBack="False"
   Enabled="true" Width="100px"    
   DataTextField="MonthEndDate" DataTextFormatString="{0:yyyy-MM-dd}" 
   DataValueField="MonthEndDate">
   <ItemTemplate>
                                <%# DataBinder.Eval(Container.DataItem, "MonthEndDate", "{0:yyyy-MM-dd}")%>
                                </ItemTemplate>
<ExpandAnimation Type="OutBounce" />
<CollapseAnimation Type="InBack" />                            
  </telerik:RadComboBox>



3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 06 Aug 2012, 06:48 AM
Hi Shan,

One of the limitations of the OnClientKeyPressing event is that it cannot be cancelled. This means that the user can type any letter in the input area of the RadComboBox (when AllowCustomText is set to True). Please take a look into this for more information.

Hope this helps.

Regards,
Princy.
0
Velkumar
Top achievements
Rank 1
answered on 29 Sep 2014, 11:24 AM
Hi Princy,

Is there a way to avoid postback when enter key is pressed in radcombobox? in my below code if user gives enter without enter any value, i need to give a alert.

alert is working fine, but the problem is page is getting postbask, i don't want that. How to resolve this??

  function productComboBox_OnClientKeyPressing(sender, eventArgs) {
            if (eventArgs.get_domEvent().keyCode == 13) {
                var combo = sender;
                if (combo.get_text().trim() == "") {
                    alert("Please enter part or all of an item description");
                }               
            }
        }

  <telerik:RadComboBox ID="productComboBox" runat="server" ClientIDMode="Static" CssClass="DetailsInput"
                                            EnableEmbeddedSkins="true" Skin="Metro" AllowCustomText="true" AutoPostBack="false"
                                            OnClientKeyPressing="productComboBox_OnClientKeyPressing">                                           
                                        </telerik:RadComboBox>
0
Nencho
Telerik team
answered on 02 Oct 2014, 08:34 AM
Hello Velkumar,

In order to achieve the desired functionality, I would suggest you to prevent the propagation of the event, when the keyCode is 13, using jQuery in the following manner :

<script type="text/javascript">
            function pageLoad() {
                $telerik.$(".rcbInput").on("keyup", function (e) {
                    if (e.keyCode == 13) {
                        var combo = $find("productComboBox");
                        if (combo.get_text().trim() == "") {
                            e.preventDefault();
                            e.stopPropagation();
                           
                            alert("Please enter part or all of an item description");
                        }
                    }
                })
            }
        </script>



Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ComboBox
Asked by
Shan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Velkumar
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or