简体   繁体   中英

Angular xeditable - how to keep edit mode open if server returns 400

how to keep open edit mode if server response with error? Now, when I click submit and send data to API, my form automatically is close, but I want to close edit mode only if server response with success, and stay opened if a response with an error. Thank you

<form editable-form name="tableform" onaftersave="saveTableConfig()" oncancel="cancel()">
<span editable-textarea="currentKlupa.description" e-name="description" e-
rows="3">Text</span>
</form>

$scope.saveTableConfig = function () {
        var config = {
            headers: {
                'Content-Type': 'application/xml',
                'X-HTTP-Method-Override': 'PUT'
            }
        };

        var configCopy = angular.copy($scope.currentConfig);

        $http.post(serviceBase + 'cd/saa/' + $stateParams.aaaID + '/config', configCopy, config)
                .success(function (data, status, headers, config) {
                    Notification.success({message: $filter('translate')('BENCH_EDITED_SUCCESSFULLY'), delay: 3000, positionY: 'bottom', positionX: 'right'});
                })
                .error(function (data, status, header, config) {
                    Notification.error({message: $filter('translate')('BENCH_EDITED_ERROR'), positionY: 'bottom', positionX: 'right'});
                });

    };

I fix this if someone need help with this. Thnx to @ckosloski (github).

You need to return a string value in your onaftersave method:

If you need to send data on server after writing to local model then you should define form's onaftersave. The result of form's onaftersave is also important for next step:

string: form will not close (eg server error) not string: form will be closed

This is my ctrl

 $scope.saveTableConfig = function () {
        var config = {
            headers: {
                'Content-Type': 'application/xml',
                'X-HTTP-Method-Override': 'PUT'
            }
        };

        var configA = angular.copy($scope.currentConfig);

        return $http.post(serviceBase + 'nnnn/config', configA, config)
                .then(function (response) {
                  //your code
                })
                .catch(function (error) {
                    //your code
               return 'return string';
            });
    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM