bootstrap-ruby / bootstrap-editable-rails

In-place editing with Twitter Bootstrap for Rails
http://rubygems.org/gems/bootstrap-editable-rails
MIT License
216 stars 52 forks source link

No error callback #13

Open russen opened 11 years ago

russen commented 11 years ago

This is related to https://github.com/vitalets/x-editable/issues/219

There is no 'error:' callback in x-ediable until version 1.4.4 !

The best you can do is add

$('a.editable-click').editable({
    ajaxOptions: {
      error: function (xhr, status, error) {
        if(xhr.status == 422){
          var msg = 'Error: ';
          errors = $.parseJSON(xhr.responseText);
          $.each(errors, function(k, v) {
            msg += k + ": " + v;
          });
          //Edit the response, to be more awesome.
          xhr.responseText = msg;
        } 
      }
    }
});

This edits the content of the error message before x-editable's error() callback fills it into Bootstrap's error blocks.

There's little to be 'fixed' until this gem is updated to use version 1.4.4, so I thought I'd document this problem with a workaround.