On pasting to a textarea, no auto grow occurs until one taps into and starts editing #4854

Closed
bonti opened this Issue Aug 16, 2012 · 3 comments

Projects

None yet

2 participants

@bonti
bonti commented Aug 16, 2012

Apologies in advance if this issue has been logged already or if it is not an issue, however if it is not I would like to know if there is a work around, business expects that on pasting a large text, the textarea control should auto grow. We have tested this out on the jquery mobile website from the iPad/iPhone/Android and see the same issue. One workaround I thought of was to access the click/tap event and force it to auto grow. How would one do that?

@jaspermdegroot
Member

@bonti

Forcing the textarea to auto grow can be done with $( "textarea" ).keyup();.
The problem might be finding the right event to bind to, because I suppose you want the textarea to grow as soon as paste is clicked in the contextmenu. I don't think the "paste" event is supported on iOS and the "change" event most probably only fires after the textarea loses focus. Maybe "input" works. Here is some code you can test with:

$( document ).on( "pageinit", function(){
    $( document ).on( "input paste change", "#mytextarea", function() {
        $( this ).keyup();
    });
});
@bonti
bonti commented Aug 17, 2012

Thank you, uGoMobi, unfortunately, that code broke the textarea autogrow, I included it in a simple script tag at the top of the page like so, I only replace dt he #mytextarea to a class I associated with the textareas on my page (my page is dynamically generated on pageshow)

$( document ).on( "pageinit", function(){
$( document ).on( "input paste change", ".testTextarea", function() {
$( this ).keyup();
});
});

I next tried it in my pageshow event, like so, but still no luck

// Handle the "page show" of the current page
$('#surveyPage').live('pageshow',
function () {
// jason call + knockout code
$(#surveyPage).on("input paste change", ".testTextarea", function () {
$(this).keyup();
});
});

I get an exception saying that the object has no "on" defined , so I am afraid, I have had no luck :(

@jaspermdegroot
Member

We have to test this again after/if we land the suggested fix for #2834

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment