Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triggering an error manually from the success() method is not working. #1075

Open
amfriedman opened this issue Feb 16, 2018 · 0 comments
Open

Comments

@amfriedman
Copy link

amfriedman commented Feb 16, 2018

I'm following the docs loyally but it is not working.

I call the server, get a 200 response that has a custom DB validation error message in the JSON that I pull out myself in the success() callback. To trigger an error state I've tried returning a simple string as the docs suggest -- but this does nothing. My x-editable element closes as if it were successful. Then I even try to call the error() callback method using this.error.call(this, response); and while this fires the error() method, it still has no impact on the unexpected x-editable element behavior.

Here is my code:

        $(".x-editable").editable({
            placement: 'right',
            url: ___('/admin/files/save_field/'),

            ajaxOptions: {
                dataType: 'json',

                error: function(response) {
             
                    if(response.status === 500) {
                        return 'Service unavailable: 500 error.';
                    }
                    else if(response.responseText) {
                        return response.responseText;
                    }
                    else {
                        return response;
                    }
                },

                success: function (response) {
                    var data = response;

                    if(data && data.errors && data.errors.flash_error) {

                        data.responseText = data.errors.flash_error[0];

                        this.error.call(this, data);

                        return data.responseText;

                    }
                }
            },

            validate: function(value) {
               
                if($.trim(value) == '') {
                    return 'This field is required.';
                }
             
            }
        });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant