Auto-resize TextAreaInput Created Through RenderUI
I'm trying to get my textAreaInputs to resize so that they display the entire area's contents by default. Following this, auto-resize textAreaInput in shiny R, I can get one to wo
Solution 1:
You can include a delay by replacing init()
with setTimeout(function(){init();}, 500);
:
jc <- "document.addEventListener('DOMContentLoaded', function(event) {
var observe;
if (window.attachEvent) {
observe = function (element, event, handler) {
element.attachEvent('on'+event, handler);
};
} else {
observe = function (element, event, handler) {
element.addEventListener(event, handler, false);
};
}
function init () {
var text = document.getElementById('text');
function resize () {
text.style.height = 'auto';
text.style.height = text.scrollHeight+'px';
}
/* 0-timeout to get the already changed text */
function delayedResize () {
window.setTimeout(resize, 0);
}
observe(text, 'change', resize);
observe(text, 'cut', delayedResize);
observe(text, 'paste', delayedResize);
observe(text, 'drop', delayedResize);
observe(text, 'keydown', delayedResize);
text.focus();
text.select();
resize();
};
setTimeout(function(){init();}, 500);
})
"
Post a Comment for "Auto-resize TextAreaInput Created Through RenderUI"