开发者

jeditable encoding & turns into & when editing

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

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?


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


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; 


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 !


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.


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, ' ');
  },
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜