materialize: Dynamically created textarea is not resizing

Description

When textarea control is created dynamically, auto-resize is not fired. $('.materialize-textarea').trigger('autoresize'); won’t help, as textarea does not have autoresize event bound to it. The only time it is set - is $(document).ready.

Maybe you can add some initialization for dynamically created controls, similar to what we can use for select elements - $('select').material_select(); ?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (11 by maintainers)

Most upvoted comments

Seems we have to add a check for data('original-height') === undefined or similar.

Workaround (set data-original-height=0) http://codepen.io/anon/pen/QvpdvO

M.textareaAutoResize(document.querySelector(‘.materialize-textarea’))

set data-original-height=0

worked for me with the version 0.98.2

Fixed in 4a3c15c

https://github.com/Dogfalo/materialize/blob/master/js/forms.js#L179-L181

http://api.jquery.com/on/

When a selector is provided, the event handler is referred to as delegated. The handler is not called when the event occurs directly on the bound element, but only for descendants (inner elements) that match the selector. jQuery bubbles the event from the event target up to the element where the handler is attached (i.e., innermost to outermost element) and runs the handler for any elements along that path matching the selector.

For me it seems to work as it should: http://codepen.io/anon/pen/xdgjzr