Form synchronization server errors

Greetings!

I’m synchronizing a form to a list. This list interacts with a server data source.

I believe I’ve set up the list correctly for undoOnError.

        webix.protoUI(
        {
            name: 'undo_list'
        }, webix.Undo, webix.ui.list)

        {
            view: 'undo_list',
            id: 'user_admin_list',
            select: true,
            url: '/api/users',
            undo: true,
            save:  {
                url: 'json->/api/users',
                updateFromResponse: true,
                undoOnError: true
            }
        }

        $$('the_form').bind($$('user_admin_list'))

Later, for a validated form …

        $$('the_form').save()

When I save the form, the form data will update the list (synchronize to the list) even when a server error occurs when saving the form (i.e. 409 error).

To clarify: the $$(‘the_form’).save() works as expected when there are no errors. The list and the data source are properly updated. The question only concerns errors encountered during the save.

However, when I use a separate form to add to the same list, the undo does work if a server error is encountered.

    var vv = $$('add_form').getValues()
    $$('user_admin_list').add(vv)
    // if a server error occurs, the item is removed from the list by undo

Right now my only workaround is to manually restore the data by intercepting onAfterSaveError or by chaining server validation calls before calling save() on the form.

Can you help point out a more elegant approach?

Best Regards,

Bruce

Unfortunately, there’s a known issue with undo method and updating data from the form (without direct editing). For now, such changes do not appear in the undo history.

> restore the data by intercepting onAfterSaveError

Our current workaround is similar. Please check the next snippet - http://webix.com/snippet/8c203340

To test the logic, select any row, enter new value and press the save ( after some time server will return error 404 and data will be reverted back )

There are two modifications here:

  • the code which triggers data saving stores old data in$undo property
  • code inonAfterSaveError handler reverts data back

We plan to include a full fix for the issue in Webix 4.2, so this workaround will not be necessary in future.

Got it - Thank You!

I appreciate the confirmation. Will continue our workaround until 4.2 arrives.

Best Regards,

Bruce