I'm using Autosize to automatically resize textboxes (height). The plugin is JS but can be used as a jQuery plugin (explained in the site). The author explains how to trigger a manual "update" event (JS) when you change the text using JavaScript. I need to do the same, but using jQuery "mode", because I'm creating textboxes dynamically using Ajax. Tried trigger() with no success.
autosize(ta); /*Pure JS*/
ta.value = "Something really long";
var evt = document.createEvent('Event');
evt.initEvent('autosize.update', true, false);
ta.dispatchEvent(evt);
Here is a piece of my source code: http://pastebin.com/049UfkGv - after $(this).autosize(); I need to trigger "autosize.update" event to redim the textbox to its new contents.
jQuery Code:
$(document).ready(function(){
window.jQuery.fn.autosize=function(){ return autosize(this); };
});
$('.edit4').each(function(){
$(this).keypress(function(event) { if (event.keyCode==13) { event.preventDefault(); };
$(this).autosize();
});
Thank you!
you can use it as follows:
autosize.update($('textarea'));
In my case the Autosize jQuery plugin could not calculate the right height, because the textarea was hidden on pageload.
The following tigger helped me out:
function showMyTextarea(){
// do your stuff here
// trigger autosize
$('textarea').trigger('autosize.resize');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With