Leave Node in Edit Mode On Cancel

4 posts, 0 answers
  1. Greg Barretta
    Greg Barretta avatar
    10 posts
    Member since:
    Jan 2010

    Posted 27 Sep 2010 Link to this post

    When a user edits a node, I want to verify a few things in Javascript. If validation fails, I call set_cancel(true). This prevents the postback but does not leave the node in edit mode. How can I accomplish this in javascript? ClientNodeEditing is fired on the OnClienNodeEditing event of the RadTreeView.

    function ClientNodeEditing(sender, eventArgs) {
         var node = eventArgs.get_node();
           var newText = eventArgs.get_newText()
          if (newText.length < 3)
          {
             alert("New entry must be 3 chars or more.");
             eventArgs.set_cancel(true);
          }
     }
  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 28 Sep 2010 Link to this post

    Hello Greg Barretta,

    Well, you can call the startEdit method of the node client object.
    Please, try that out and let me know the results.

    Hope this is going to help you!


    Regards,
    Nikolay Tsenkov
    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
  3. Greg Barretta
    Greg Barretta avatar
    10 posts
    Member since:
    Jan 2010

    Posted 28 Sep 2010 Link to this post

    Yea, that was the first thing I tried, but it does not work. You can see it go into edit mode for a split second then comes out of edit
    mode. Below is scaled down code with no code behind that reflects what I am trying to do. 


    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
      
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
      
      
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
      
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
       <script type="text/javascript">
      
            function ClientNodeEditing(sender, eventArgs) {
                var node = eventArgs.get_node();
                  var newText = eventArgs.get_newText()
                 if (newText.length < 3)
                 {
                    alert("New entry must be 3 chars or more.");
                    eventArgs.set_cancel(true);
                    node.startEdit();
                }
            }
      
            function onClientContextMenuItemClicking(sender, args) {
                var menuItem = args.get_menuItem();
                var treeNode = args.get_node();
                var tree = $find("<%= RadTreeView1.ClientID %>");
                tree.unselectAllNodes();
      
                menuItem.get_menu().hide();
      
                switch (menuItem.get_value()) {
                    case "Rename":
                        treeNode.startEdit();
                        break;
                   }
            }
       
        </script>
    </telerik:RadScriptBlock>
      
      
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
      
      
     <telerik:RadAjaxPanel ID="treePanel" runat="server"
                    HorizontalAlign="NotSet" LoadingPanelID="loadingPanelEmpty" >
        <telerik:RadTreeView ID="RadTreeView1" runat="server"
        OnClientContextMenuItemClicking="onClientContextMenuItemClicking"
        OnClientNodeEditing="ClientNodeEditing">
         <Nodes>
           <telerik:RadTreeNode runat="server" Text="My First Node">
               <Nodes>
                   <telerik:RadTreeNode runat="server" Text="Child Node">
                   </telerik:RadTreeNode>
               </Nodes>                             
           </telerik:RadTreeNode>
           <telerik:RadTreeNode runat="server" Text="My Second Node">
           </telerik:RadTreeNode>
       </Nodes>
       <ContextMenus>
                    <telerik:RadTreeViewContextMenu ID="MainContextMenu" runat="server">
                        <Items>
                            <telerik:RadMenuItem Value="Rename" Text="Rename ..." PostBack="false">
                            </telerik:RadMenuItem>
                         </Items>
                        <CollapseAnimation Type="None" />
                    </telerik:RadTreeViewContextMenu>
                </ContextMenus>
        </telerik:RadTreeView>
        </telerik:RadAjaxPanel>
      
    </asp:Content>
  4. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 01 Oct 2010 Link to this post

    Hello Greg Barretta,

    Could you, please call node edit inside a setTimeout statement:
    setTimeout(function () { node.startEdit(); }, 0);

    Hope this is going to help you!


    Regards,
    Nikolay Tsenkov
    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
Back to Top