Search code examples
x-editable

x-editable render html error response


We have a system where customer information is editable in-line. When someone puts in an email that already exists, I want to return the error message:

Email already exists. <a href='/find-duplicates/id'>Click here to find possible duplicates of this customer</a>

I would like the user to be able to click on the link when s/he sees the error message. The error message is very easy to send; it's rendering the html that's the problem.


Solution

  • Trying to display same kind of link in x-editable field error as @iateadonut.

    For anyone wanting to display html in x-editable errors, assuming you have the error with html sent back from server with response status code different from 500 (400 maybe) try :

    $(function() {
      $('#your_field_id').editable({
        error: function(response, newValue) {            
            if(response.status === 500) {
                return 'Service unavailable. Please try later.';
            } else {
                var error = $.parseHTML( response.responseText )
                $(".editable-error-block").html(error)
            }
         },
      });
    })
    

    Mostly html parsing response error and injecting it inside x-editable error block. Found in x-editable doc, options.