Fix handling of newlines in textarea input

This commit is contained in:
Jean-Marc Fontaine 2012-12-13 15:00:16 +01:00 committed by vitalets
parent 19f227f83c
commit 1159e26e34
2 changed files with 8 additions and 2 deletions
src/inputs
test/unit

@ -53,7 +53,13 @@ $(function(){
}
var lines = html.split(/<br\s*\/?>/i);
for (var i = 0; i < lines.length; i++) {
lines[i] = $('<div>').html(lines[i]).text();
var text = $('<div>').html(lines[i]).text();
// Remove newline characters (\n) to avoid them being converted by value2html() method
// thus adding extra <br> tags
text = text.replace(new RegExp(String.fromCharCode(10), 'g'), '');
lines[i] = text;
}
return lines.join("\n");
},

@ -58,7 +58,7 @@ $(function () {
})
asyncTest("should replace <br> with newline (on show) and back (on save)", function () {
var v = '12<br>3&lt;i&gt;4<br />56',
var v = '12<br>\n3&lt;i&gt;4<br />56',
e = $('<a href="#" data-type="textarea" data-pk="1" data-url="post.php">'+v+'</a>').appendTo(fx).editable(),
v1 = '12\n3<i>4\n56',
vnew = "12\n3<b>4\n56\n\n78",