materialize icon indicating copy to clipboard operation
materialize copied to clipboard

Dynamically created textarea is not resizing

Open TetianaP opened this issue 9 years ago • 27 comments

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(); ?

TetianaP avatar Apr 27 '17 02:04 TetianaP

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

DanielRuf avatar Apr 27 '17 11:04 DanielRuf

It is working fine for the version 0.98.1 (the one you used in your example), but it does not work for the latest one - 0.98.2.

TetianaP avatar Apr 27 '17 22:04 TetianaP

@TetianaP you are right, seems we have another regression bug here.

http://codepen.io/anon/pen/QvpdNM https://www.diffchecker.com/RqQVQKHI

Would have to compare the compiled components and triage this bug.

DanielRuf avatar Apr 28 '17 09:04 DanielRuf

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

DanielRuf avatar Apr 28 '17 09:04 DanielRuf

@fega @tomscholz please add a label like needs-pr so I know that I plan to create a PR.

DanielRuf avatar Apr 28 '17 09:04 DanielRuf

@DanielRuf I don't think that we need a needs-pr label. I mean, pull request are always welcome and such a label would would make things more complicated than necessary

tomscholz avatar Apr 28 '17 09:04 tomscholz

@tomscholz ok. Will add the issue number to my personal todo list.

DanielRuf avatar Apr 28 '17 10:04 DanielRuf

@TetianaP please test the change and if this breaks anything

Applied here

DanielRuf avatar Apr 28 '17 15:04 DanielRuf

Fixed in 4a3c15c

acburst avatar May 01 '17 18:05 acburst

@DanielRuf that works, thanks everyone! How soon could we expect it to be released?

TetianaP avatar May 01 '17 21:05 TetianaP

@TetianaP you could also use one of the solutions

http://stackoverflow.com/a/16951315/753676 http://stackoverflow.com/a/18049685/753676

should also work with the update command

DanielRuf avatar May 01 '17 21:05 DanielRuf

@DanielRuf Thanks, it will work, but in this case need to bundle all js together, as materialize-css/dist/js/materialize.min.js was not updated and it contains old implementation from forms.js.

TetianaP avatar May 04 '17 05:05 TetianaP

@TetianaP just clone and run Grunt in the directory of Materialize to build a new file using the js_compile task.

DanielRuf avatar May 04 '17 08:05 DanielRuf

set data-original-height=0

worked for me with the version 0.98.2

eduardoalvara2 avatar May 23 '17 21:05 eduardoalvara2

Exactly ;-) https://github.com/Dogfalo/materialize/issues/4613#issuecomment-297950328

DanielRuf avatar May 23 '17 21:05 DanielRuf

Hi same problem here on version v0.99.0

  • I add a textarea dynamically to the DOM
  • I set its value with $('#myTextArea').val($('#myTextArea').attr('data-original-value'));
  • I trigger the autoresize event $('#myTextArea').trigger('autoresize');

The data-label overlapped the text, if I click on the textarea the label goes correctly on top the text and all goes fine then.

The HTML

<div class="row">
    <div class="input-field col s12">
        <textarea id="bot-message-input"
                  class="materialize-textarea"
                  data-original-value="<%= text %>"
                  data-original-height="0"></textarea>
        <label for="bot-message-input">The message the bot will print</label>
    </div>
</div>

The bug state at the page load

textarea-bug-state

The ok state after clicking on the textarea

text-area-ok-state

mister-good-deal avatar Jul 05 '17 03:07 mister-good-deal

@DanielRuf I have a same problem on 0.99.0

knight7024 avatar Sep 08 '17 20:09 knight7024

@knight7024 did you try 0.100.0 or newer?

DanielRuf avatar Sep 08 '17 20:09 DanielRuf

@DanielRuf yes i did it but nothing changed

and modal cannot be loaded well on 0.100.2

sry i fixed it by adding this in tag

knight7024 avatar Sep 08 '17 20:09 knight7024

Is anyone else still having this problem? I just upgraded from .98 to .100.2 and this is an issue. It wasn't an issue in the .98 version.

Any help would be appreciated.

SmboBeast avatar Oct 10 '17 04:10 SmboBeast