Topic: Modal to forms with autogrowth textarea
Pierre M pro asked 7 years ago
Hi,
When i put a form in a modal in which there are textareas with autogrowth ( with the js script answered in a previous topic, or the script autosize.js), the modal got a really weird comportment : it adds a lot of space in the textarea but when i remove the autogrowth function, everything goes well.
Do you have any solution for this problem ?
Thank you very much.
Pierre
Marta Wierzbicka staff answered 7 years ago
Hi,
try this code:
HTML:
<!--Material textarea--> <div class="md-form mt-5"> <textarea type="text" id="form7" class="md-textarea pt-1 py-0 pb-0"></textarea> <label for="form7" class="pb-2">Material textarea</label> </div>
CSS:
textarea.md-textarea { min-height: 6rem; }
JS:
jQuery.fn.extend({ autoHeight: function () { function autoHeight_(element) { return jQuery(element) .css({ 'height': 'auto', 'overflow-y': 'hidden' }) .height(element.scrollHeight); } return this.each(function() { autoHeight_(this).on('input', function() { autoHeight_(this); }); }); } }); $('textarea').autoHeight();
Best,
Marta
Pierre M pro answered 7 years ago
jQuery.fn.extend({
autoHeight: function () {
function autoHeight_(element) {
return jQuery(element)
.css({ 'height': 'auto', 'overflow-y': 'hidden' })
.height(element.scrollHeight);
}
return this.each(function() {
autoHeight_(this).on('input', function() {
autoHeight_(this);
});
});
}
});
$('textarea').autoHeight();
I also tried the autosize.js (from http://www.jacklmoore.com/autosize/)
Marta Wierzbicka staff answered 7 years ago
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Pro
- Premium support: No
- Technology: General Bootstrap questions
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No