Unable To Get Editor Ajax Error Messages To Show

Unable To Get Editor Ajax Error Messages To Show

paulbpaulb Posts: 2Questions: 1Answers: 0
edited May 2016 in Free community support

I'm using Datatables 1.10.12 with the 1.5.6 editor + bootstrap themes for both. I'm unable to get the form error popup to display when I get an error while submitting an inline edit.

Here's what the code looks like: https://gist.github.com/pawl/1a2fc5554f0528eda620c3900a27527d#file-datatable-html-L40

The errors returned from the server are in json format with response code 401 or 500, and look like this: {"error": "Must be logged in to edit products."}

I've resorted to displaying errors like this:

    editor.on('submitError', function (e, xhr, err, thrown, data){
      alert(JSON.parse(xhr.responseText).error);
    });

What am I doing wrong? Does the bootstrap theme even have the ability to display the popup errors?

Note: I also tried this with Datatables 1.10.11 and Editor 1.5.5, but had the same issue.

Update: Hmm, I might be mistaken. I guess there's no default pop-up error to tell the user there was an error with inline editing. Looks like an error only shows when the edit modal is enabled: https://imgur.com/NurR9Aw

Update 2: I ended up displaying the error in a modal, like this:

    // display editor ajax errors in a modal
    editor.on('submitError', function (e, xhr, err, thrown, data){
      var error_message = JSON.parse(xhr.responseText).error;
      $('#errorModal').modal('show');
      $('#error-modal-body').text(error_message);
      this.close(); // prevent 2nd form submit
    });

Answers

  • paulbpaulb Posts: 2Questions: 1Answers: 0
    edited May 2016

    I was expecting something like the red text from the error message that x-editable displays below the form that failed to submit: https://imgur.com/H9fIe8l

  • allanallan Posts: 63,794Questions: 1Answers: 10,514 Site admin

    This is a bit of a limitation in Editor at the moment and how it deals with non-2XX return codes I'm afraid. If you were to return 200: { "error": "..." } it would correctly show up.

    Editor 1.6 will handle return non-2XX return codes much better, but at the moment your work around is currently the best way to handle it.

    Allan

This discussion has been closed.