Welcome Guest Search | Active Topics | Sign In | Register

TreeView - ClientSideOnNodeRename for autoformat string? Options
Luis Angel
Posted: Wednesday, February 27, 2008 3:18:58 AM
Rank: Member
Groups: Member

Joined: 2/25/2008
Posts: 14
Hi,
I'm trying to use the ClientSideOnNodeRename client script function to modify the text that the user has write (to format it, like "cod-text" should be changed to "cod - text", and things like this one)

But I've been unable to make it work properly. I've tryed several aproaches:
· Change the newText parameter value and make the function to return true: With this code the edit textbox dissapears with the edited node text. If I start to edit another tree node then the first node will reapear but with the original text.
· Change newText and return false. Then the user text is set correctly to the node text, without taking into account my changes.
· use node.setText() function to change the node text and return false: then I get a javascript error message (something like "argument not valid" -it's translated from spanish so maybe the english message is not exactly like that).
· use node.setText() and return true. Then I get the dissapearing text like in the second try, and I get the same javascript error when trying to edit another node.

My javascript node looks like this:
Code: JavaScript
function FormateaNombreNodo(treeview, node, newText)
{
var nodeKey = node.getValue().substr(0,1);
        if (nodeKey==KEY_OP) { 
        var idx = newText.indexOf(SEP_COD_VALUE);
        var code, name;
        if (idx<0){
            code = newText;
            name = newText;
        }
        else {
            code = newText.substr(0,idx);
            if (idx==newText.length) name="";
            else name = newText.substr(idx+1);
        }   
        newText = code.toUpperCase() + " " + SEP_COD_VALUE + " " + name; 
    }
    node.setText(newText);
    return false;
}


(changing the last two lines depending on try case...)

Is there a way to accomplish this? is there a better way?

thanks in advance
eo_support
Posted: Wednesday, February 27, 2008 6:29:16 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

None of those will work. You need to let the event handler to finishes it work and then change it. Specifically, you can use window.setTimeout to do it:

Code: JavaScript
var g_Node = null;
var g_NewText = null;

function FormateaNombreNodo(treeview, node, newText)
{
   g_Node = node;
   g_NewText = FormatNewText(newText);
   window.setTimeout("UpdateNodeText()", 10);
} 

function UpdateNodeText()
{
   g_Node.setText(g_NewText);
}


Thanks
Luis Angel
Posted: Thursday, February 28, 2008 1:17:07 AM
Rank: Member
Groups: Member

Joined: 2/25/2008
Posts: 14
Thank you very much.

It works perfectly .



You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.