I am kind of new to the world of web development, but i am being able to solve all the challenges implementing the plug-in... except this one... (at least for now :))
I am using edit ext. and I am not being able to manage this in case of a "invalid" server validation...
I am using the "save" event in order to implement an ajax call to the server, like this:
save: function(event, data){
request = $.ajax({
url: "xhr/rename_object.php",
type: "POST",
data: {
object_data_record_id: node.data.record_id,
object_name: data.input.val()
}
});
request.done(function(result){
if (result.retcode>0) {
// I would like to return false from "save" if the condition is verified...
}
// Currently it is allways returning true, as outside the function I don't know out to test result.retcode...
}
Many thanks !!!
I saw the recipe many thanks, but I still have the same problem, when the server returns a logical error like "invalid title..." I am not able to exit false from the save event and keep the editor open...
Many thanks
tx again!
How about this...
RECIPE to handle server/application validation errors on editing...
Tx a lot again!
--------
$("#your_tree").fancytree({
extensions: ["edit"],
source: {
<your source>
},
edit: {
triggerStart: ["clickActive", "f2", "dblclick", "shift+click", "mac+enter"],
beforeEdit: function(event, data){
var node = data.node;
if ( <your_contidions_to_avoid_editing> ) {
return false;
}
},
save: function(event, data){
var node = data.node;
var newTitle = data.input.val();
var originalTitle = data.orgTitle;
// Save data.input.val() or return false to keep the editor open
request = $.ajax({
<your_ajax_call_to_validate_and_update_title_in_server|db)>
});
request.done(function(result){
// Server might return an application error
if (result.retcode>0) { // validation error
// Do something related to application error here
}
else {
// server returned OK
node.setTitle(<user_typed_value or server_updated_value>);
// important! exit sucessfull editing
node.editEnd(false);
}
});
request.fail(function(result){
// maybe update title with original value
node.setTitle(originalTitle);
});
request.always(function(){
$(data.node.span).removeClass("pending");
});
// Always return false except when receives server validation successfully
return false;
},
close: function(event, data){
// Editor was removed. If we started an async request, mark the node as pending
if( data.save ) {
$(data.node.span).addClass("pending");
}
},
},
});