Fix handling of newlines in textarea input
This commit is contained in:

committed by
vitalets

parent
19f227f83c
commit
1159e26e34
@ -53,7 +53,13 @@ $(function(){
|
|||||||
}
|
}
|
||||||
var lines = html.split(/<br\s*\/?>/i);
|
var lines = html.split(/<br\s*\/?>/i);
|
||||||
for (var i = 0; i < lines.length; 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");
|
return lines.join("\n");
|
||||||
},
|
},
|
||||||
|
@ -58,7 +58,7 @@ $(function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
asyncTest("should replace <br> with newline (on show) and back (on save)", function () {
|
asyncTest("should replace <br> with newline (on show) and back (on save)", function () {
|
||||||
var v = '12<br>3<i>4<br />56',
|
var v = '12<br>\n3<i>4<br />56',
|
||||||
e = $('<a href="#" data-type="textarea" data-pk="1" data-url="post.php">'+v+'</a>').appendTo(fx).editable(),
|
e = $('<a href="#" data-type="textarea" data-pk="1" data-url="post.php">'+v+'</a>').appendTo(fx).editable(),
|
||||||
v1 = '12\n3<i>4\n56',
|
v1 = '12\n3<i>4\n56',
|
||||||
vnew = "12\n3<b>4\n56\n\n78",
|
vnew = "12\n3<b>4\n56\n\n78",
|
||||||
|
Reference in New Issue
Block a user