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

OnItemsRequested won't fire when user copy/paste text in input field

13 Answers 212 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nicolas
Top achievements
Rank 1
Nicolas asked on 27 Jan 2011, 04:54 PM
Hi telerik community,

I've been working on an interesting issue regarding the RadComboBox and the autocomplete feature. My problem is, when a user copy paste a value in the input field instead of typing it, the OnItemsRequested won't get fired and will cause my page to fail because, in my scenario, I need to get the value associate with the text entry.

Just to make it clear, it works like a charm when the user type his search.

Here's my implementation of the RadComboBox
<telerik:RadComboBox ID="contractNumber" runat="server" Width="165px" Height="150px"
     CssClass="form"
    AllowCustomText="true"
    MarkFirstMatch="true"
    EmptyMessage="Search (5 characters min)*"
    EnableLoadOnDemand="true"
    EnableItemCaching="true"
    IsCaseSensitive="false"
    MinFilterLength="5"
    EnableOverlay="true"
    OnItemsRequested="ContractNumber_ItemRequested"
    DataTextField="Key"
    OnClientBlur=""
    DataValueField="Value">
</telerik:RadComboBox>

Now, this ComboBox is located in a pop-up. When I click my OK button there's some javascript going on
function returnToParent()
{
    //create the argument that will be returned to the parent page
    var oArg = new Object();
 
    if ($find("<%= contractNumber.ClientID %>").get_value())
        oArg.contractNumber = $find("<%= contractNumber.ClientID %>").get_value();
 
    //Close the RadWindow and send the argument to the parent page
    if (oArg.contractNumber)
    {
        var oWnd = GetRadWindow();
        oWnd.close(oArg);
    }
    else
        alert("Please provide a contract number or a system ID");
}

As you can see, if my RadComboBox doesn't fire the ItemRequested event when a user paste some text in it (which is the source of the problem here), the get_value() will always return null, and that's the bad thing.

So how can I get this feature working without having to ask the user to focus-out/focus-in or delete a character and retype it to fire the event.

As always, thanks in advance for your Advises

ND

13 Answers, 1 is accepted

Sort by
0
Nicolas
Top achievements
Rank 1
answered on 31 Jan 2011, 10:51 PM
Any advise at all? How can I get this to work when copy/pasting value in the radcombobox input?
0
Kalina
Telerik team
answered on 01 Feb 2011, 10:06 PM
Hi Nicolas,

After user pastes some text at RadComboBox that uses Load On Demand - the ItemsRequested event fires properly - you can test this here.

However pasting a text does not mean that there will be a selected item at RadComboBox input.
When user actually selects a RadComboBoxItem - the value or this item is set as a value of the RadComboBox control. After that you are able to get the RadComboBox value with get_value() method.

You can try to set explicitly a selected item at RadComboBox when handling OnClientClick event of OK button in this way:

var combo = $find('<%=contractNumber.ClientID%>');
 
if (combo.findItemByText(combo.get_text()) != null) {
    combo.findItemByText(combo.get_text()).select();
    //Close the RadWindow and send the argument to the parent page
    //...
}
else {
    alert("Please provide a contract number or a system ID");
}


All the best,
Kalina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Nicolas
Top achievements
Rank 1
answered on 01 Feb 2011, 10:25 PM
Hi Kalina,

in you example, the event gets fired on focusing the radcombobox, and the copy paste is only filtering results that are already there. This is the expected behavior in most of the cases. What so ever, in my scenario, I have a minimal filter length of 5 characters which will prevent the OnItemRequested event to get fired on focusing and therefore, when the user paste a value in the combobox, there's no filtering and selection done because there is no value in the combobox.

The flow of execution that I'm trying to achieve is the following:
  1. The user copy a value from another window or another application
  2. The user focus the RadComboBox control
  3. The system doesn't fire the OnItemsRequested event since the MinFilterLenght criteria isn't respected
  4. The user paste the copied text in the RadComboBox input
  5. If the MinFilterLenght criteria is respected then fire the OnItemsRequested event.
  6. The system filters the returned result with the pasted criteria.
  7. The system mark the first match.
So, I believe that my problem is how do I get the OnItemRequested fired after the client has paste a string longer than my minfilterlenght=5, then after this, getting the first item in the list that meet the criteria of the search (the pasted string)?
0
Accepted
Kalina
Telerik team
answered on 07 Feb 2011, 02:14 PM
Hi Nicolas,

Thank you for the clarification.
You are right - when user clicks in the RadComboBox input a request for items is performed.  This behaviour is not correct because the MinFilterLength has been set to "5".
We will research what causes this issue.

Meanwhile please try the following:
1.   Add this function on your page after the RadScriptManager
var $ = $telerik.$;
var $T = Telerik.Web.UI;
var $p = Telerik.Web.UI.RadComboBox.prototype;
var onPaste = $p._onPaste;
 
$p._onPaste = function(e) {
    text = this.get_text();
    this._updateFilterText = true;
 
};

2.   Handle the OnClientItemsRequesting event in this way:
function OnClientItemsRequestingHandler(sender, eventArgs) {
    if (eventArgs.get_text().length < 5) {
        eventArgs.set_cancel(true)
        this._compensateValuePropertyChangeEvent = true;
    }
    else {
        eventArgs.set_cancel(false);
    }
}

Please download the attached sample page, give it a try and let me know if this helps.
If the issue persists - please send me a simplified working page that reproduces it.

Kind regards,
Kalina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Nicolas
Top achievements
Rank 1
answered on 07 Feb 2011, 10:06 PM
Hi Kalina

It seems to be working fine, the only thing is I embed the javascript in the page load function.

function pageLoad() {
  var $ = $telerik.$;
  var $T = Telerik.Web.UI;
  var $p = Telerik.Web.UI.RadComboBox.prototype;
  var onPaste = $p._onPaste;
 
  $p._onPaste = function (e) {
      text = this.get_text();
      this._updateFilterText = true;
  };
}

One question though, what's Telerik.Web.UI.RadComboBox.prototype? I don't understand the "prototype" part of this.

thank you very much for your help.

ND
0
Kalina
Telerik team
answered on 08 Feb 2011, 10:13 PM
Hello Nicolas,

The prototype in fact envelops all the methods and properties of the control client-side object.
Let me suggest you take a look at this article where the conception of "prototype" is explained clearly.

Regards,
Kalina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 10 May 2011, 01:06 PM
Is the MinFilterLenght still broken in RadComboBox (as has been confirmed by Telerik in a bug report) so that you have to complement it with a javascript function of your own, like below?

    function radComboBoxUser_OnClientItemsRequesting(sender, eventArgs)
    {
        debugger;
        if (eventArgs.get_text().length <= 4)
            eventArgs.set_cancel(true)
        else
            eventArgs.set_cancel(false);
    }

0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 10 May 2011, 01:25 PM
Can confirm myself that this bug still exists, even though it was confirmed a few months ago. But the javascript work around presented above works, but is hard to maintain over time. Would be nice if this was corrected.

One thing though we noticed, it seems that you now have to wrap the code in the previous post with:

<telerik:RadScriptBlock ID="radScriptBlockCustomer" runat="server">
</telerik:RadScriptBlock>

or it won't work any more (it used to do before).

This could however be related to something beyond the control of Telerik.
0
Kalina
Telerik team
answered on 12 May 2011, 03:42 PM
Hello Patrik Johansson,


I'm afraid that this bug is not resolved yet, please excuse us for the inconvenience.
Currently we are completing the Q1 2011 Service Pack 2 Release, but we are definitely going to consider it for the next major Q2-release.

Kind regards,
Kalina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jeff
Top achievements
Rank 1
answered on 16 May 2013, 04:22 PM
how about now - has this bug been fixed yet?  if so, what release was it in?  I'm experiencing the issue - but only in IE8.

please advise.  thanks!
0
Hristo Valyavicharski
Telerik team
answered on 21 May 2013, 02:39 PM
Hi Jeff,

This issue has been resolved in the latest internal builds. The fix will be included in the upcoming beta release, scheduled for 22nd of May 2013.

Regards,
Hristo Valyavicharski
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jeff
Top achievements
Rank 1
answered on 21 May 2013, 02:47 PM
Thanks for the reply - that's great!  However, I'm wondering when it will be released 'non-beta' as this is a production issue that we are experiencing here.  Any idea when that will be?  Surely we will test with the beta version to see if things work, but would like to know your final release date plans.  Thanks!
0
Hristo Valyavicharski
Telerik team
answered on 24 May 2013, 12:12 PM
Hi Jeff,

Q2 2013 Beta was released on 22nd of May, Q2 2013 is expected to be released in the middle of June (12th). You can subscribe for Release History RSS feeds.

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Nicolas
Top achievements
Rank 1
Answers by
Nicolas
Top achievements
Rank 1
Kalina
Telerik team
improwise
Top achievements
Rank 1
Iron
Iron
Jeff
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or