bgrins / ExpandingTextareas

jQuery plugin for elegant expanding textareas
http://bgrins.github.com/ExpandingTextareas/
MIT License
261 stars 73 forks source link

Would be nice to handle programmatic changes to the textarea #58

Closed ghost closed 9 years ago

ghost commented 9 years ago

If I jQuery( "textarea" ).val( "Some very long string..." ) the textarea doesn't expand. Maybe a listener for "onchange" could be added, or at least a manual function : .expanding( "update" )?

For my own use I've added an .expanding( "update" ) method for my use (copied the idea of .expanding( "destroy" )). I thought .expandingTextarea( "resize" ) (from the v.0.1 version) used to do this?

bgrins commented 9 years ago

I think the call to .expanding( "update" ) should work without needing to change the plugin: https://github.com/bgrins/ExpandingTextareas/blob/master/expanding.js#L32. Is it not?

domchristie commented 9 years ago

@paul-acre88 the plugin listens for input, change, and keyup (in cases where input is not supported).

Unfortunately .val() does not trigger input or change event, but calling .val('Some very long string...').change() should do the job.

I suppose because there is a straight forward jQuery equivalent, this hasn't been implemented. But I quite like the idea of:

$('textarea').expanding('val', 'Some very long string...');
bgrins commented 9 years ago

Right, textarea.val('Some very long string...').change() is the best way to handle this, and is documented in the README: https://github.com/bgrins/ExpandingTextareas#manual.

I wish there was a way to make jQuery val() work without having a workaround, but I don't think there is a way.

bgrins commented 9 years ago

$('textarea').expanding('val', 'Some very long string...');

I actually prefer our existing suggestion as opposed to adding a new thing to the API for it, since either way is going to require some extra work from users, but the current suggestion will still work even if someone removes away expanding.js so changing this would add a bit more friction to removing the dependency.

ghost commented 9 years ago

Thanks, guys. Missed the solution in the README.

If it's jQuery (or whatever spec or agreed-upon standard) that says the "change" event shouldn't fire on programmatic updates to a textarea, then doesn't seem like y'all need to fix anything, sound like a problem/feature further up the line. :)

domchristie commented 9 years ago

Good thinking.

I think .val('foo').change() is quite a common pattern

On Thursday, 8 January 2015, Brian Grinstead notifications@github.com wrote:

$('textarea').expanding('val', 'Some very long string...');

I actually prefer our existing suggestion as opposed to adding a new thing to the API for it, since either way is going to require some extra work from users, but the current suggestion will still work even if someone removes away expanding.js so changing this would add a bit more friction to removing the dependency.

— Reply to this email directly or view it on GitHub https://github.com/bgrins/ExpandingTextareas/issues/58#issuecomment-69251757 .

Dom Christie t: 07709143652 e: christiedom@gmail.com