8

I'm using jeditable and having some encoding issues. If I enter &, save, and then try to edit it shows up as &.

Easily reproducible here: http://www.appelsiini.net/projects/jeditable/default.html

Edit the Normal textarea and enter &&&, save and then edit again and you'll see it. How can I fix this?

Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012

5 Answers5

5

A way better solution.... even for compressed js file.

Search for line :

self.revert     = $(self).html();

replace with

self.revert     = $(self).text();

Solution no1 would not work if you would like to have "&" in your editable field Sollution no2 is version dependent

Alex
  • 59
  • 1
  • 2
  • It works. Thank you. Would be nice to see jEditable source file updated. It's still the same code from 2009 – Maksym Kozlenko Sep 11 '13 at 12:37
  • Fixes that particular issue, but creates others. Try typing in some HTML into your jEditable. Something like an anchor tag... – elsurudo Aug 18 '14 at 15:29
2

solution:

input_content = $('<textarea/>').html(self.revert).val();

This converts the input to a html_safe type format. This goes in around line 247 to replace:

input_content = self.revert; 
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
1

There is a pull request for this problem on the github repo.

The quick fix is as Alex said. If you don't know what to change, look at the file on the pull request.

The better fix is to pester the repo owner, since this pull request is two years old.

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
ShadowCat7
  • 804
  • 8
  • 16
1

I encountered the same issue, here is what I edited in the jquery.jeditable.js (v 1.7.1) file :

replace l.176 :

self.editing    = true;
self.revert     = $(self).html(); 
$(self).html('');

by

self.editing    = true;
self.revert     = $(self).html().replace(/&amp;/g,"&");
$(self).html('');

This is a simple regexp replacing &amp; by & and it did the job !

Xasz
  • 101
  • 1
  • 8
0

This can be done without changing the jeditable source code by using the data callback in the options:

  // Called after onedit, the 'data' callback allows 
  // manipulation of data to be displayed in edit forms
  'data': function(value, settings) {
    return html_decode(value);
  },

where html_decode() is defined, for example like this:

  html_decode: function (str) {
        return String(str)
            .replace(/&gt;/g, '>')
            .replace(/&lt;/g, '<')
            .replace(/&#39;/g, "'")
            .replace(/&quot;/g, '"')
            .replace(/&amp;/g, '&')
            .replace(/&nbsp;/g, ' ');
  },
stef
  • 107
  • 1
  • 6