0
I’ll try to explain my problem. Initially I consult the information, where the textarea automatically adjusts the size according to the text that returns from the database. I’m doing it this way:
$(".area").on('keyup input keypress keydown change', function(e) {
var tamanhoMin = $(this).attr('rows') * $(this).css('line-height').replace(/[^0-9\.]+/g, '');
$(this).css({'height': 'auto'});
var novoTamanho = this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"));
if (tamanhoMin > novoTamanho) novoTamanho = tamanhoMin;
$(this).css({'height': novoTamanho});
}).css({
'overflow':'hidden',
'resize':'none'
}).delay(0).show(0, function() {
var el = $(this);
setTimeout(function () {
el.trigger('keyup');
}, 100);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="modal-header">
<h4 class="modal-title">IDENTIFICAÇÃO</h4>
<a style="float:right" type="button" name="edit" id="'.$row["codigo"].'" data-toggle="modal" href="#ad_Modaleditar" class="btn btn-primary edit_anamnese">Editar</a>
</div>
<form id="insert_form1">
<div class="row clearfix">
<div class="col_half">
<label>O que pode Despoletar a Crise/Descompensação</label>
<div class="textarea_field"> <span><i aria-hidden="true" class="fa fa-comment"></i></span>
<textarea style="padding-left:35px" class="form-control area" readonly="true">1
1
1
1
1
1
1
1
</textarea>
</div>
</div>
</div>
</form>
So far so good.
Then when I click the edit button opens a new form, which receives the information to be edited, but here the textarea does not automatically adjust:
<div class="col_half">
<label>O que pode Despoletar a Crise/Descompensação</label>
<div class="textarea_field"> <span><i aria-hidden="true" class="fa fa-comment"></i></span>
<textarea style="padding-left:35px" class="form-control area1" id="Despoletar" name="Despoletar"></textarea>
</div>
</div>
js:
$(".area1").on('keyup input keypress keydown change', function(e) {
var tamanhoMin1 = $(this).attr('rows') * $(this).css('line-height').replace(/[^0-9\.]+/g, '');
$(this).css({'height': 'auto'});
var novoTamanho1 = this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"));
if (tamanhoMin1 > novoTamanho1) novoTamanho1 = tamanhoMin1;
$(this).css({'height': novoTamanho1});
}).css({
'overflow':'hidden',
'resize':'none'
}).delay(0).show(0, function() {
var el1 = $(this);
setTimeout(function () {
el1.trigger('keyup');
}, 100);
});
and stay that way:
Can help identify the problem?
Use
$(document).on('keyup input keypress keydown change', '.area1', function(e) {
. I think that’s the problem. If it’s not that, give a warning here.– Sam
@Sam changing the line you indicated I get the error
Uncaught TypeError: Cannot read property 'display' of undefined
– Junior
True. I’ll take a look here. But, apart from this error, the textarea worked as expected?
– Sam
@Sam, yes textarea works like mirror, but does not adjust in height
– Junior