views:

60

answers:

1

Hello,

I am using jqTouch for my web app which is running on different phones including the iPhone. The issue I have is with the iPhone.

When I set a value on the form using the jQuery function val(), the keyboard opens up automatically. I don't want that to happen when I am changing the value or just adding a default value to a pre-exisiting form.

Do you know a way to block the keyboard from popping up when val() is called on a form input? I tried to use $(':focus').blur() right after the call to val() but it is ugly. The keyboard opens and closes very fast which is not acceptable.

Laurent

+1  A: 

If that works, you could always use jQuery aop to add a $(':focus').blur() to val calls. Something like this might work.

jQuery.aop.after( {target: jQuery, method: 'val'}, 
    function(response){
       if(typeof(response) == 'string')
         $(':focus').blur();

       return response;
});

I'm not quite sure that that target would work, but you could play around with this sort of thing and see if you can't get it working. If you didn't want to go adding side-effects to jQuery methods (probably a terrible idea), you could always craft your own function called valNoKeyboard(), either as a standalone function or jQuery plugin. I think the jQuery plugin route makes more sense, unless there's a better way to do this.

Stefan Kendall
I will play with it and let you know if it works for me. Thanks.
Laurent Luce
It is working for me with small changes. Thanks again for the tip.jQuery.aop.after( {target: jQuery, method: 'val'}, function(response) { if(typeof(response) == 'string') $(':focus').blur() return response; });
Laurent Luce
Glad you got it working :). I'lle dit my answer to reflect what worked for you.
Stefan Kendall