Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3744

Error() never displayed for postSubmit (does work for preSubmit)

$
0
0

Code as follows

            var storageEditor = new $.fn.dataTable.Editor({
                ajax: {
                    create: {
                        type: 'POST',
                        url: '/api/Fax/AddFaxStorage',
                        contentType: 'application/json',
                        data: function (d) {
                            return JSON.stringify(d.data[0]);
                        }
                    },
                    edit: {
                        type: 'POST',
                        url: '/api/Fax/ModifyFaxStorage',
                        contentType: 'application/json',
                        data: function (d) {
                            var firstKey;
                            var firstVal;
                            for (var i in d.data) {
                                firstKey = i;
                                firstVal = d.data[i];
                                break;
                            }
                            firstVal.FaxStorageId = firstKey;
                            var myReturn = JSON.stringify(firstVal);
                            return myReturn;
                        }
                    },
                    remove: {
                        type: 'POST',
                        url: '/api/Fax/DeleteFaxStorages',
                        contentType: 'application/json',
                        data: function (d) {
                            var returnData = [];
                            var item = {};
                            $.each(d.data, function (key, val) {
                                item = val;
                                returnData.push(item);
                                item = {};
                            });
                            var myReturn = JSON.stringify(returnData);
                            return myReturn;
                        },
                        /*
                        error: function (xhr, error) {
                            alert(xhr.responseJSON.Message);
                            //storageEditor.error(xhr.responseJSON.Message);
                        */
                    }
                },
                table: "#storageTable",
                idSrc: "FaxStorageId",
                fields: [
                    {
                        label: "Name",
                        name: "Name",
                    },
                    {
                        label: "Type",
                        name: "StorageType",
                        type: "select",
                        placeholder: "Select...",
                        fieldInfo: "",
                    },
                    {
                        label: "Path",
                        name: "Path",
                    },
                    {
                        label: "Username",
                        name: "Username"
                    },
                    {
                        label: "Password",
                        name: "Password",
                        type: "password"
                    }
                ],
                formOptions: {
                    main: {
                        onReturn: false,
                        onEsc: false,
                        onBackground: false
                    }
                }
            }).on('open', function (e, mode, action) {
                if (action === "edit")
                    storageEditor.disable("StorageType");
                else
                    storageEditor.enable("StorageType");
            }).on('postSubmit', function (e, json, data, action, xhr) {
                storageEditor.error('Test Error');
                setTimeout(function () {
                    storageEditor.error('');
                }, 5000);
                return false;
            });

I've tried with and without the setTimeout and never see the error either way. (Ultimately I would want the error to stay there forever rather than disappear anyway). a JS Alert works fine in the the postSubmit as well.

This is being used for a Delete button when there is contention on the server side, returning a 400 with a message as to why the record can't be deleted. Is there a good example of this somewhere to handle a 400 error properly with postSubmit and display using .error()?


Viewing all articles
Browse latest Browse all 3744

Trending Articles