Resize text in Meteor

I am trying to create an editing page where a user can edit their content in a text box to fit the content, and I use this plugin to do this: http://www.jacklmoore.com/autosize/

But when I access the edit page, the text box does not resize to fit the content, this only happens if I refresh the page manually. Here is the code:

<template name="postEdit">
    <textarea autofocus name="content" type="text" value="">{{content}}</textarea>
</template>

Template.postEdit.rendered = function() {
     $('textarea').autosize(); 
};

I also tried with Meteor.defer, but it does not work:

Template.postEdit.rendered = function() {
    Meteor.defer(function() {
    $('textarea').autosize();
 });     
};

When I refresh the page manually and the text box finally resizes, the html text environment changes for this:

<textarea class="review" name="review" type="text" value="" placeholder="Blablabla" style="overflow: hidden; word-wrap: break-word; resize: horizontal; height: 664px;"></textarea>

Are there any problems with my code or is my approach wrong?

Thank.

+4
4

" " " jQuery Autoresize" , , , :

Template.hello.rendered = function(){
    $('textarea').autosize().show().trigger('autosize.resize');
}
+4

, DOM , . :

$(function(){
    $("textarea").autosize();
});
0

I am not a jQuery expert, but if I remember correctly, you can do this:

Template.postEdit.rendered = function() {
     $(this.find('textarea')).autosize(); 
};
0
source

Just try this way

$(document).ready(function(){
 $('textarea').autosize();   
});
-1
source

Source: https://habr.com/ru/post/1529699/


All Articles