Javascript for "Paste" in RadComboBox "OnClientKeyPressing" event -
in onclientkeypressing
event of radcombobox
, checking if entered text inside radcombobox
greater 5 characters, enable asp:button
, if not disable asp:button
.
both radcombobox
, asp:button
inside radgrid
.
this works perfetcly if type in 5 or 5+ characters manually, not if paste 5 or 5+ characters inside radcombobox
, if paste asp:button
remains disable.
reason is: when paste in radcombobox
, onclientkeypressing
event raise , since key(ctrl+v) pressed 1 time, length of text 0 , per condition (if length < 3, disable button) remains disable.
please note length starts 0 not 1.
i know reason dont know how make detect whole text-length after paste in radcombobox
below javascript till now:
<telerik:radcodeblock id="rcb" runat="server"> <script type="text/javascript"> function handlekeypress(sender, eventargs) { var len = sender.get_text().length; var comboid = sender.get_id(); var btnsearchid = comboid.replace("ddlaccountcode", "btnsearch"); var btnctrl = document.getelementbyid(btnsearchid); //code chk ctrl + v var e = eventargs.get_domevent(); if (e.keycode == 86 && e.ctrlkey) { var len2 = sender.get_text().length; //-------issue here : pasted text/length 0 (as key pressed 1 time) alert(len2); if (len2 > 4) { //alert("ctrl+v : enable"); btnctrl.disabled = false; //enable } else { //alert("ctrl+v : disable"); btnctrl.disabled = true; //disable } } else if (eventargs.get_domevent().keycode != 8 && len > 4) { //alert("chk manually entered text"); btnctrl.disabled = false; //enable } else if (eventargs.get_domevent().keycode == 8 && len > 4){ //alert("backspace enable"); btnctrl.disabled = false; //enable } else { btnctrl.disabled = true; //disable } } </script> </telerik:radcodeblock>
html:
<telerik:radgrid id="radgrid1" runat="server" autogeneratecolumns="false" onneeddatasource="radgrid1_needdatasource"> <mastertableview> <columns> <telerik:gridtemplatecolumn headertext="acc"> <edititemtemplate> <telerik:radcombobox id="ddlaccountcode" runat="server" height="200" width="260" allowcustomtext="true" onclientkeypressing="handlekeypress" > <items> <telerik:radcomboboxitem text="gg" /> <telerik:radcomboboxitem text="gg1" /> <telerik:radcomboboxitem text="gg3" /> </items> </telerik:radcombobox> <asp:button id="btnsearch" runat="server" text="search" onclick="btnsearch_click" onclientclick="buttonclicked()" usesubmitbehavior="true" /> </edititemtemplate> </telerik:gridtemplatecolumn> </columns> </mastertableview> </telerik:radgrid>
the onclientkeypressing
event triggered between time when key pressed , when control populated text key press. means show text's length - 1 in normal cases user typing, , have no text yet when user pastes it.
i suggest using onclienttextchange
event instead, trigger after text in control has changed. in case shouldn't need write conditional statement handle ctrl+v
input. however, trigger after combo box has lost focus.
another solution, if need trigger when user presses key , not after combo box loses focus, wrap code inside settimeout
call 1 ms second parameter, allow control have text updated before checked against code.
Comments
Post a Comment