Paste the Content at the Cursor point

6 posts, 2 answers
  1. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 20 Feb 2013 Link to this post

    Hi,
    I am ussing radeditor with custom radcombobox in it. when i add the content from combobox to rad editor it paste the value on top of the content but i need to be Paste at the cursor point.



    Thanks
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Feb 2013 Link to this post

    Hi Dhamodaran

    When the user clicks on the combobox control the selection in the editor's content area is lost. The code below demonstrates how to make all comboboxes' items unselectable to prevent selection lost in RadEditor's content area. 
    In addition the getSelectedItemValue function is attached to the OnClientSelectedIndexChanged event of RadCombobox and pastes the selected item value at cursor position in the editor when the user selects a combobox item:
    Try the following code snippet and let me know your concern.
    aspx:
    <telerik:radeditor runat="server" ID="RadEditor1" Content="test mest"></telerik:radeditor>
    <div style="padding: 15px 0 0 0;font-family:Arial;font-size:14px;">
        RadComboBox with static items:
        <telerik:RadComboBox OnClientSelectedIndexChanged="getSelectedItemValue" OnClientLoad="OnClientLoad" ID="RadCombobox1" runat="server">
            <Items>
                <telerik:RadComboBoxItem Text="Item1" Value="<strong>Item 1</strong>" />
                <telerik:RadComboBoxItem Text="Item2" Value="<strong>Item 2</strong>" />
                <telerik:RadComboBoxItem Text="Item3" Value="<strong>Item 3</strong>" />
            </Items>
        </telerik:RadComboBox>
    </div>
    <div style="padding: 15px 0 0 0;font-family:Arial;font-size:14px;">
        RadComboBox with Load-On-Demand:
        <telerik:RadComboBox OnClientSelectedIndexChanged="getSelectedItemValue" OnClientItemsRequested="OnClientItemsRequested" OnClientLoad="OnClientLoad" ID="RadCombobox2" runat="server"
            OnItemsRequested="RadCombobox2_ItemsRequested" EnableLoadOnDemand="true"></telerik:RadComboBox>
    </div>
    C#:
    using Telerik.Web.UI;
           
    protected void RadCombobox2_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
            for (int i = 0; i < 10; i++)
            {
                RadCombobox2.Items.Add(new RadComboBoxItem("Item" + i.ToString(), "<strong>Item " + i.ToString() + "</strong>"));
            }
    }
    JS:
    <script type="text/javascript">
    function OnClientLoad(combobox, args)
    {
        makeUnselectable(combobox.get_element());
    }
       
    function OnClientItemsRequested(combobox, args)
    {
        $telerik.$("*", combobox.get_dropDownElement()).attr("unselectable", "on");
    }
           
    //Make all combobox items unselectable to prevent selection in editor being lost
    function makeUnselectable(element)
    {
        $telerik.$("*", element).attr("unselectable", "on");
    }
         
    function getSelectedItemValue(combobox, args)
    {
      var value = combobox.get_value();
      //alert("The selected combobox value is: " + value);
      //get a reference to RadEditor client object
      //and paste the selected combobox item content in it
      var editor = $find("<%=RadEditor1.ClientID%>");
      editor.pasteHtml(value);
    </script>

    Thanks
    Princy
  3. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 20 Feb 2013 Link to this post

    Hi Princy,
                            I am using the Same code -  editor.pasteHtml(value) . Its works good, content is pasted on the top of the Existing content. I want the content to paste on the Cursor point.








    Thanks




  4. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Feb 2013 Link to this post

    Hi Dhamodharan

    Take a look at the following Knowledge Base Article of Telerik which explains your same issue for more information and let me know your concern.
    Pasting content from RadComboBox item in RadEditor at cursor position

    Thanks
    Princy.
  5. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 21 Feb 2013 Link to this post

    Hi Princy,

      Your both  code works. I have done the mistake in calling the  OnClientItemsRequested function in the ClientItemsRequesting event. Now it works perfectly


     



    Thanks
  6. Frank
    Frank avatar
    24 posts
    Member since:
    Nov 2010

    Posted 07 Mar 2013 Link to this post

    Hi Princy,

     

    Following this thread we achieved having the RadComboBox visible with its items. Now we want people to have the ability to type into it to find their item quicker. We set the HighlightTemplatedItems="true" and Filter="Contains".

     

    Problem now is you can’t select the item to start typing. You can press delete to remove the current selected item and start typing, but then it inserts the selected item again at the beginning of the RadEditor.

     

    Any idea how to solve this so users can use the type-option and search within the RadComboBox ?


    Yours,
    Frank.
Back to Top