Skip to content

Commit

Permalink
feat: autosize text area inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondas committed Apr 28, 2024
1 parent 986aa33 commit 51714b4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion templates/edit.html
Expand Up @@ -418,4 +418,22 @@ <h5 class="mb-3">{% trans %}Edit zone{% endtrans %} "{{ zone_name_to_display }}"
</tr>
{% endif %}
</table>
</div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
var textareas = document.querySelectorAll('textarea');

textareas.forEach(function(textarea) {
textarea.addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = this.scrollHeight + 'px';
});

// Trigger the 'input' event on page load if the textarea has content
if (textarea.value !== '') {
textarea.dispatchEvent(new Event('input'));
}
});
});
</script>

2 comments on commit 51714b4

@SkySai1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it is nice!

@edmondas
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SkySai1 I thought and realised that the same thing should be done in other windows where there is a textarea, so included it to add and edit records views.

Please sign in to comment.