views:

532

answers:

2

I'm attempting to trigger Jquery autocomplete from outside the field.

I'm running an on screen Jquery keyboard, so the normal keyup keydown events are not fired.

I can not use Jquery.Event or trigger() because I'm stuck with Jquery 1.2.6.

I am aware there are other onscreen keyboards out there, but all the other ones I've tested have 'lag'. fieldselection adds a little, but this was reasonably fast as is. Just.. no autocomplete firing.

I'm not above rolling my own autocomplete, but the rest of the code is so simple and I just want to make sure I'm not missing something simple. :)

fieldselection is a modified version that supports backspace from here: http://designshack.co.uk/tutorialexamples/vkeyboard/

<script type="text/javascript" src="js/jquery.fieldselection.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Keeps track of last input that was clicked in.
    $('input[type="text"], textarea').focus(function() {
        selectedInput = $(this);
    });
    // Add autocomplete.
    $('#search-customers-input').autocomplete(
      'js/ps-action.php?searchCustomers=1');
    // Attach action to virtual keyboard keys.
    $('.keypad-literal').click(function() {
        selectedInput.replaceSelection($(this).text(), true);
        // I don't chain these as for some reason it doesn't work.
        selectedInput.focus();
        // Can't use as I'm on 1.2.6
        //var key = $(this).text(); 
        //var e = jQuery.Event("keydown");
        //e.which = key.charCodeAt(0);
        //selectedInput.trigger(\'focus\').trigger(e);
    });
});
</script>
<button type=button class="keypad-key keypad-literal">q</button>
<button type=button class="keypad-key keypad-literal">w</button>
<button type=button class="keypad-key keypad-literal">e</button>
... etc ...
<button type=button class="keypad-key large"
  onClick='selectedInput.parents("form").submit();'>Enter</button>
A: 

have you try jQuery.noConflict()? (docs here: http://api.jquery.com/jQuery.noConflict/)

<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type='text/javascript'>
    // create namespace for jquery 1.4.2
    var j142 = $.noConflict(true);
</script>
<script type='text/javascript' src='jquery-1.2.6.min.js'></script>

<script type='text/javascript'>
    // jquery 1.4.2 codes here
    j142(document).ready(function() {
        j142('p#new').text('jquery 1.4.2 yay!');
        });

    // jquery 1.2.6 codes here, falling back to the default $
    $(document).ready(function() {
        $('p#old').text('jquery 1.2.6 yay!');
        });
</script>
widyakumara
No. I wasn't aware of that.. but.. I actually tried replacing 1.2.6 with 1.4.2 (something I can't do in production) and everything seems to work, but calling Event and trigger for every click really slowed it down too.
Daren Schwenke
A: 

Hey Darren, I'm having same issue. Using Virtual Keyboard and it doesn't work with autocomplete.

Did you find a solution to trigger the autocomplete event of an input?

mrtdncr