Detect paste event in iOS in textarea?

1,306 views
Skip to first unread message

ScottP

unread,
Feb 6, 2011, 10:46:13 PM2/6/11
to phonegap
I know this isn't specfically phonegap - but there's a lot of talented
people in group who may know the answer.
Is there a way to detect a paste event in a textarea element on iOS?
I've tried onchange but that doesn't fire until you hit the done
button and the keyboard closes.
The reason I'd like to do this is that I am dynamically resizing my
textarea so my app user doesn't have to use the 2-finger scroll on the
textarea if there is more text than can be shown.
onkeydown seems to work well, but if my user pastes text into the
textarea it doesn't resize until they tap a key or close the keyboard.
I've tried ontouchstart and ontouchend but they don't seem to get
fired.
So if I could detect a paste event, I could just call my resizing
function from that.
Or is it possible to detect this via obj-c side of things and pass
that to js?
Any suggestions are appreciated.
Scott

jcesar

unread,
Feb 7, 2011, 10:38:28 AM2/7/11
to phonegap
maybe you can try with onChange

André Fiedler

unread,
Feb 7, 2011, 10:43:29 AM2/7/11
to phon...@googlegroups.com
have you tried listen for the "paste" event? Should work.(?)

2011/2/7 jcesar <jcesar...@gmail.com>
--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

André Fiedler

unread,
Feb 7, 2011, 10:44:45 AM2/7/11
to phon...@googlegroups.com

ScottP

unread,
Feb 7, 2011, 2:35:19 PM2/7/11
to phonegap
The onchange doesn't register until the keyboard is closed. I'd like
to resize the textarea as soon as the user pastes into it.

I looked at onpaste but it doesn't seem to be supported in iOS.
Desktop Safari supports it but not mobile.
Thanks for the suggestions though.

On Feb 7, 10:44 am, André Fiedler <fiedler.an...@googlemail.com>
wrote:
> take a look at:
>
> http://developer.apple.com/library/mac/#documentation/AppleApplicatio...
>
> 2011/2/7 André Fiedler <fiedler.an...@googlemail.com>
>
>
>
> > have you tried listen for the "paste" event? Should work.(?)
>
> > 2011/2/7 jcesar <jcesarmob...@gmail.com>
> >> For more info on PhoneGap or to download the code go towww.phonegap.com- Hide quoted text -
>
> - Show quoted text -

André Fiedler

unread,
Feb 7, 2011, 4:47:30 PM2/7/11
to phon...@googlegroups.com
Hm, bad that it isn´t supported. Another hint, you could run a function periodical (every 300 ms or so) and check if the textareas content has changed. Should work.


2011/2/7 ScottP <scott.a...@gmail.com>

ScottP

unread,
Feb 7, 2011, 10:37:27 PM2/7/11
to phonegap
I thought maybe you were on to something. I tried posting a message to
the log using setInterval('myMessage();',300) with onfocus on the
textarea. Unfortunately, no messages. Also tried it with my resizing
function instead of the log message and nothing.
I'm starting to think that when the keyboard is open, the only events
you can get at are onkeydown, onkeyup etc...
Oh well, I'll just have to educate my users that you can 2-finger
swipe the textarea.
Thanks again.

On Feb 7, 4:47 pm, André Fiedler <fiedler.an...@googlemail.com> wrote:
> Hm, bad that it isn´t supported. Another hint, you could run a function
> periodical (every 300 ms or so) and check if the textareas content has
> changed. Should work.
>
> 2011/2/7 ScottP <scott.a.padi...@gmail.com>
> > towww.phonegap.com-Hide quoted text -

André Fiedler

unread,
Feb 8, 2011, 3:21:42 AM2/8/11
to phon...@googlegroups.com
use something like:

var yourTextarea = documentGetElementById('textarea');
var taText = '';

setInterval(function(){
    if(yourTextarea.value != taText){
      // resize your Textarea
      taText = yourTextarea.value;
   }
},300);

2011/2/8 ScottP <scott.a...@gmail.com>

ScottP

unread,
Feb 8, 2011, 6:55:19 AM2/8/11
to phonegap
I'll give it a try tonight. Thanks!

On Feb 8, 3:21 am, André Fiedler <fiedler.an...@googlemail.com> wrote:
> use something like:
>
> var yourTextarea = documentGetElementById('textarea');
> var taText = '';
>
> setInterval(function(){
>     if(yourTextarea.value != taText){
>       // resize your Textarea
>       taText = yourTextarea.value;
>    }
>
> },300);
>
> 2011/2/8 ScottP <scott.a.padi...@gmail.com>
> > > > towww.phonegap.com-Hidequoted text -
>
> > > > > - Show quoted text -
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "phonegap" group.
> > > > To post to this group, send email to phon...@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > phonegap+u...@googlegroups.com
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > > > For more info on PhoneGap or to download the code go
> > towww.phonegap.com
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "phonegap" group.
> > To post to this group, send email to phon...@googlegroups.com
> > To unsubscribe from this group, send email to
> > phonegap+u...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > For more info on PhoneGap or to download the code go towww.phonegap.com- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages