PDA

View Full Version : TreeNode edit call to server help



MoShAn480
30 Jul 2007, 10:04 AM
Hi,

i am playing around wit the dependency.js example with the tree nodes, and i really like the edit function where you can click the component and it converts to a text field which can be edited. I was wondering if there is a callback for the edit so when an edit occurs, you can send data to the server, check something, and either allow the edit to occur on the server and client or not.

Below is the code i am referring to:



var node = new xt.TreeNode({
text: text,
iconCls:'cmp',
cls:'cmp',
type:'cmp',
id: id,
cmpId:id,
allowDelete:true,
allowEdit:true,
qtip:'Message will go here'

});
I tired:

beforecomplete: callBack

but that does not seem to t work. Any help would be greatly appreciated. I tired looking up the documentation, but i was not able to find anything. I cannot even find "allowEdit" config option in the documentation either....

thanks!

MoShAn480
13 Aug 2007, 11:33 AM
The following code did the trick:



var ge = new xt.TreeEditor(ctree, {
allowBlank:false,
blankText:'A name is required',
selectOnFocus:true,
cancelOnEsc: true,
completeOnEnter: true
});

ge.on('beforestartedit', function(){
if(!ge.editNode.attributes.allowEdit){
return false;
}
});

//inline message group name editing - ajax enabled
ge.on('beforecomplete', function(editor, value, startValue){
var id = sm.getSelectedNode().id;

var wasSuccess = true;
var node = croot.findChild('text',value);

if ((node != null) && (node.text != startValue)){
showExtModalAlert('Error Updating Group Name', 'Another group with that name already exists, please try again.');
wasSuccess = false;
}
else if (value.length > 40){
showExtModalAlert('Error Updating Group Name', 'The group name length cannot exceed 40 characters, please try again.');
wasSuccess = false;
}
else if (value != startValue){
var content = "doAsRemoteCall=true&messageGroupName=" + value + "&action=editMessageGroupName&id=" + id + "&queueId=" + queueId;
doExtAjaxCall("queueCannedMessage.do", content, null);
}

return wasSuccess;
});



The "beforecomplete" event is key. Returning true or false from the event handler will cause the value to change or revert.

AspWhiz
1 Dec 2007, 5:57 PM
I know this post is old, but I tried exactly what was posted and it does NOT revert back to the orig value AND it does not cancel the edit box.

Is there any developer around to explain why? I've also put another post in about this. I've tried everything.

hendricd
2 Dec 2007, 8:48 AM
Just handle that behaviour yourself:



editor.on('beforecomplete', function(editor, value, startValue){
if(spellsTrouble(value)){

editor.cancelEdit(true);
if(editor.updateEl && editor.boundEl){
editor.boundEl.update(startValue);
}
editor.hide();
editor.editing = false;
return false;
}
});

or, assign the TextField a custom validator and let it handle the rest:



var ge = new xt.TreeEditor(ctree, {
allowBlank:false,
blankText:'A name is required',
selectOnFocus:true,
cancelOnEsc: true,
completeOnEnter: true,
validator:function(value){
return isOK(value) || 'Your Node input is invalid'; //true or error message
}
});

hunkybill
18 Dec 2007, 1:12 PM
Just handle that behaviour yourself:



editor.on('beforecomplete', function(editor, value, startValue){
if(spellsTrouble(value)){

editor.cancelEdit(true);
if(editor.updateEl && editor.boundEl){
editor.boundEl.update(startValue);
}
editor.hide();
editor.editing = false;
return false;
}
});


I do this and get a blowout on too much recursion...??

var args = Array.prototype.slice.call(arguments, 0); line 1501 of ext-all-debug.js (Ext.2.0 final)...

Not sure why cancelling a complete event goes all recursive??

MoShAn480
20 Dec 2007, 3:52 PM
This i used this code in version 1.1. I have not tired it in 2.0.