Skip to content

Commit

Permalink
handle newlines and html conversions correctly in area_notes
Browse files Browse the repository at this point in the history
enabling linebreaks in django cause the html tags to show up in edit mode.
requirement is to have newlines handled accordingly in both viewing and editing.
  • Loading branch information
henrinie committed Sep 22, 2024
1 parent 37aef83 commit e82eea0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion signbank/dictionary/templates/dictionary/gloss_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ <h4 class="modal-title" id="glossvideo{{glossvideo.pk}}-ModalLabel">{% blocktran
{# Translators: Information about a Gloss #}
<tr>
<th>{% blocktrans %}Notes:{% endblocktrans %}</th>
<td class='edit edit_area_notes' id='notes'>{% value gloss.notes|linebreaks %}</td>
<td class='edit edit_area_notes' id='notes'>{% value gloss.notes|linebreaksbr %}</td>
</tr>
{# Translators: Information about a Gloss #}
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h4>{% blocktrans %}Translation equivalents{% endblocktrans %}</h4>
<header>
<h4>{% blocktrans %}Notes{% endblocktrans %}</h4>
</header>
<p>{% if gloss.notes %}{{gloss.notes|linebreaks}}
<p>{% if gloss.notes %}{{gloss.notes|linebreaksbr}}
{% else %}<em>{% blocktrans %}No notes.{% endblocktrans %}</em>{% endif %}</p>
</section>
</div>
Expand Down
14 changes: 13 additions & 1 deletion signbank/static/js/gloss_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,19 @@ function configure_edit() {
type : 'textarea',
width : 400,
rows : 3,
onblur : 'ignore',
// onedit & callback & onreset: handle newlines and html conversions in jeditable.
onedit : function(_settings, original) {
// Use innerText which contains newlines `\n`
original.innerHTML = original.innerText;
},
onreset : function(_settings, original) {
// Replace newlines with `<br>` for returned value
original.replace(/\n/g, '<br>');
},
callback : function(value, _settings) {
// Replace newlines with `<br>` for returned value
this.innerHTML = value.replace(/\n/g, '<br>');
},
});
$('.edit_url').editable(edit_post_url, {
type : 'text',
Expand Down

0 comments on commit e82eea0

Please sign in to comment.