0

I made a keyboard plugin. When I click on values of the keyboard it succesfully fills the input box, but it doesn't trigger my event.

In a nutshell:

<form>
    <input id='testinput' type='text' name='test' value='' />
</form>

jQuery:

$('input').focus(function(){
    $('input').keyboard().show();
});

$('#test-input').on('input', function() {
   alert('change'); 
});

The code for the keyboard is a bit too big to show it here. It is attached in the fiddle. When I manually write something in the input it is triggered, but not via the keyboard.

Can someone point me in the right direction?

5
  • $("a").trigger("click"); api.jquery.com/trigger Commented Oct 6, 2014 at 14:11
  • Tip: A typo here? $('#test-input') Commented Oct 6, 2014 at 14:14
  • From the documentation: input: Occurs when the text content of an element is changed through the user interface. Commented Oct 6, 2014 at 14:16
  • I saw it, thanks, forgot to change it back while editing, but that doesn't change a thing unfortunately.. Commented Oct 6, 2014 at 14:16
  • possible duplicate of jQuery 'input' event Commented Oct 6, 2014 at 14:17

1 Answer 1

1

You are programatically inserting the characters when a user clicks so you will need to manually trigger the "input" event handler also in your plugin

click: function(e) {
  e.stopPropagation()
  e.preventDefault()
  this.select()
  this.$element.trigger('input')
}

FIDDLE

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! I had it almost right myself, but instead of input I had the ID of the input. Many thanks my hero!
Its Failing Buddy,Try the combination some i/p from keybord some from input ,it fails
@ShekharPankaj what's failing? I couldn't get it to fail - Are you sure the input has the focus when you are using the keyboard?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.