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>