Max Length on Node Edit

9 posts, 1 answers
  1. Kai
    Kai avatar
    23 posts
    Member since:
    Jun 2009

    Posted 28 Aug 2009 Link to this post

    Is there a way to set the max length for the edit box when editing an item in the tree view?  I can see that when editing the name of a node in the tree view, the editable area is an input box.  With input boxes, you should be able to set a maximum length.  I just need a way to set the maximum length for the editable area so when a user goes to rename a node in the tree view, they can't give it a really long name.

    Kai Thao
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Aug 2009 Link to this post

    Hi Kai Thao,

    Try the following approach for setting the MaxLength when editing the tree node.

    ASPX:
     
    <telerik:RadTreeView ID="RadTreeView1" OnClientNodeEditStart="OnClientNodeEditStartHandler" runat="server" AllowNodeEditing="True"
        <Nodes> 
         . . . 
        </Nodes> 
    </telerik:RadTreeNode> 

    JavaScript:
     
    <script type="text/javascript"
    function OnClientNodeEditStartHandler(sender, eventArgs) 
       var node = eventArgs.get_node(); 
       var textInput = node.get_inputElement();     
       textInput.width = "150"
       textInput.maxLength = 4; // Set the MaxLength 
    </script> 

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kai
    Kai avatar
    23 posts
    Member since:
    Jun 2009

    Posted 31 Aug 2009 Link to this post

    Thanks.  That worked perfect.

    Kai Thao
  5. iairgood
    iairgood avatar
    3 posts
    Member since:
    Mar 2007

    Posted 01 Apr 2010 Link to this post

    Hello,

    The approach to set the maximum length on the edit input box worked, but it appears that only 50 characters of the edited text are actually saving.  Is there a way to increase the maximum length of the edit input to something greater than 50, say 255?

    Thanks,
    Ian
  6. Marbry
    Marbry avatar
    26 posts
    Member since:
    Aug 2012

    Posted 21 Sep 2011 Link to this post

    I can't find any way to set that on the server side other than perhaps a custom attribute.  Is there something I can set on the node that will be carried over to use for the MaxLength on the generated textbox?

    I would think there would be something like,
    AllowEdit = true;
    MaxEditLength = 30;
  7. Marbry
    Marbry avatar
    26 posts
    Member since:
    Aug 2012

    Posted 22 Sep 2011 Link to this post

    I believe I have this working now.

    I query the schema info when the page loads from a stored procedure.
    SELECT
          TABLE_NAME,
          COLUMN_NAME,
          DATA_TYPE,
          CHARACTER_MAXIMUM_LENGTH
    FROM [INFORMATION_SCHEMA].[COLUMNS]


    Retrieve that from function that calls the stored proc and store it in a list.
    private List<usp_GetSchemaResult> SchemaResults = GetSchema();


    And set an attribute on the nodes as they're created.
    RadNode1.Attributes.Add("MaxLength", (from r in SchemaResults where r.COLUMN_NAME == "Field1Name" select r.CHARACTER_MAXIMUM_LENGTH.ToString()).First<string>());


    Then I get that attribute value on the client side when the node is edited and set the MaxLength for the input element.
    node.startEdit();
    // set max length
    var max = node._attributes.getAttribute("MaxLength");
    if (max != null && max != "")
    {
        var editRef = node.get_inputElement();
        editRef.maxLength = max;
    }
  8. jc mag
    jc mag avatar
    106 posts
    Member since:
    Aug 2005

    Posted 07 Mar 2012 Link to this post

    I'm using this code:
    function OnClientNodeEditStartHandler(sender, eventArgs)  
    {  
       var node = eventArgs.get_node();  
       var textInput = node.get_inputElement();      
       textInput.width = "150";  
    .....
    }  
    but the width of the textbox in edit mode doesn't work...
    Does it work for you?

  9. Marbry
    Marbry avatar
    26 posts
    Member since:
    Aug 2012

    Posted 07 Mar 2012 Link to this post

    I think that needs to textInput.style.width.

    I'm not doing that directly on the default box, but I do have a templated text box that I expand when it's selected for editing.  Here's the client edit block handler for that.

    var element = node.get_element();
    if (element != null)
    {
        var textBox = $telerik.findElement(element, "Property_TB" + newIDVal);
        if (textBox != null)
        {
            textBox.disabled = false;
            textBox.setAttribute("rows", "8");
            textBox.style.width = "400px";
            eventArgs.set_cancel(true);
            sender._hideContextMenus();
            return true;
        }
    }
  10. jc mag
    jc mag avatar
    106 posts
    Member since:
    Aug 2005

    Posted 07 Mar 2012 Link to this post

    it works, thanks! ;)
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017