Issue
I have a HTML textarea in which someone can place their own text. This text has to be able to support enters. So when I submit this textarea to the database, everything works. For this example, I have put the following text in the textarea:
I now placed an enter. And I want to save this.
Thanks!
Now when I try to load this text back from the database to the browser, I get an Unexpected End of File error. See image below.
I have looked everywhere, but I don’t know how to fix this. The only 'solution' I can find, is to remove the enters. This however only works in Jquery/JS and not in Python (flask). Also, this is not really a solution, because the message needs to be with enters/new lines.
Could you people help me with this?
Thanks in advance!
My code (as you can see, I already tried some things): The textarea itself:
<div class="col-" id="textarea-div">
<label><b>Your message: </b></label>
<br>
<textarea rows="5" cols="60" id="campagne_bericht" name="campagne_bericht" maxlength="300" class="form-control" placeholder="Plaats uw bericht hier..." required></textarea>
<script>
// $("#campagne_bericht").keyup(function(e) {
// if(e.keyCode === 13) {
// console.log("Enter");
// //{# $("#campagne_bericht").val($("#campagne_bericht").val() + "test"); #}
// let bericht = $("#campagne_bericht").val().replace(/[\u00A0\u1680\u180e\u2000-\u2009\u200a\u200b\u202f\u205f\u3000]/g, 'test');
// console.log($("#campagne_bericht").val());
// }
// //{# $("#campagne_bericht").text($("#campagne_bericht").text().replace("\n", "Enter")); #}
// });
// Key Press Listener Attachment for #area.
$("#campagne_bericht").keypress(function (event) {
// If the key code is not associated with the ENTER key...
if (event.keyCode == 13) {
// Otherwise prevent the default event.
// event.preventDefault();
// remove new lines from the textarea
// let bericht = $("#campagne_bericht").val().replace(/\s+/g, '\n');
let bericht = $("#campagne_bericht").val().replace(/\r\n|\r|\n/g, '\r');
$("#campagne_bericht").val(bericht);
console.log(bericht);
}
});
</script>
</div>
To load the text into the textarea with JQuery:
$('#campagne_bericht').val('{{ campagne[7] }}'); //{{ campagne[7] }} is to load the message from Python to the html.
Solution
In order to put multiline text in JS you can do something like this:
$('#campagne_bericht').val({{ campagne[7] }}
);
Basically using `` instead of ''
Answered By - Khushnud
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.