Get callback server response with form.save()

Hello,

I have one form binded with one list.

the list is : var usrGrpList = {
        rows: [
            {
                view: "list",
                id: "usrGrpList",
                url: "server/users/load_users_groups.php",
                save: "server/users/save_users_group.php",
                select: true,
                multiselect: true,
                template: "#name#",
            }

        ],

When I click on save button in form, I want to use form.save() and insert in list AFTER check if the server response is correct.

I try events with dataProcessors but the problem is that the data are inserted in list before gets events.

I want to use the power of data processors and callback in save function like webix.ajax().post do.

Is it possible ?

Thank you.

You can do something like next

var data = form.getValues();
webix.ajax().post("some.php", data).then(function(response){
     data.id = response.id;
     list.add(data);
});

if you are using dataprocessor on list, you need to add the new record without triggering data saving by dataprocessor.

var data = form.getValues();
webix.ajax().post("some.php", data).then(function(response){
     data.id = response.id;
     webix.dp(list).ignore(function(){
         list.add(data);
     })
});

Thank you for your response.

So if I use this method, I lose the flexibility of “save” method, I must determine when it’s an insert or update and I can’t use the variable “webix_operation” on server. There 's no possibility to get callback response with dataprocessor ?

Yep, you need to choose, are you using the default data saving functionality, where data is added to the list first and only after that is sent to a server-side. Or you need to have a custom data saving logic, where data is added to the list only after confirmation from the server side.

Default data saving is “optimistic” it shows the newly added record before it really saved in DataBase, and allows you to define a error handler, so if record was not saved, you can show some message to the user, or delete the wrong record.

Thanks :wink:

how to implement non ‘optimistic’ saving?