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

Max Length on Node Edit

8 Answers 263 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kai
Top achievements
Rank 1
Kai asked on 28 Aug 2009, 08:46 PM
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

8 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 29 Aug 2009, 05:57 AM
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.
0
Kai
Top achievements
Rank 1
answered on 31 Aug 2009, 12:42 PM
Thanks.  That worked perfect.

Kai Thao
0
iairgood
Top achievements
Rank 1
answered on 01 Apr 2010, 06:10 PM
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
0
Marbry
Top achievements
Rank 1
answered on 21 Sep 2011, 11:20 PM
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;
0
Marbry
Top achievements
Rank 1
answered on 22 Sep 2011, 04:52 PM
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;
}
0
jc mag
Top achievements
Rank 1
answered on 07 Mar 2012, 04:19 PM
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?

0
Marbry
Top achievements
Rank 1
answered on 07 Mar 2012, 04:46 PM
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;
    }
}
0
jc mag
Top achievements
Rank 1
answered on 07 Mar 2012, 05:49 PM
it works, thanks! ;)
Tags
TreeView
Asked by
Kai
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kai
Top achievements
Rank 1
iairgood
Top achievements
Rank 1
Marbry
Top achievements
Rank 1
jc mag
Top achievements
Rank 1
Share this question
or