Laurent Luce
Laurent Luce

Reputation: 929

jQuery val() opens keyboard

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

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 - it should only happen when the user tries to type in a value.

Is there 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 the keyboard still opens and closes very fast, which isn't acceptable.

Upvotes: 2

Views: 735

Answers (1)

Stefan Kendall
Stefan Kendall

Reputation: 67822

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.

Upvotes: 1

Related Questions