I am writing a draggable html div as:
And it looks like this:
But I cannot input anything like a normal input div as: <input />
.
It does not response for any key events.
I have tried to use stopPropagation
to stop the event to its parents as:
input.onclick = function ( evt ) {
evt.stopPropagation();
console.log( 'input got clicked' );
};
$( input ).on( 'keydown', function ( evt ) {
evt.stopPropagation();
console.log( 'input got keydown' );
} );
where the input
is:
let input = document.createElement( 'input' );
input.setAttribute( 'type', 'text' );
and with console.log( input )
:
but it does not help. (And for the later keydown event, no output is given in the console.)
Can anyone suggest me a way to debug this problem? It really drives me crazy. Thanks!
PS: Chrome is used.
Update: I find the problem, but do not know the reason.
It is because I decorate the parent dom as jquery draggable, and I need to cancel the <input class='x-leaf'/>
as:
$('#input-parent').draggable({
containment: 'window',
cancel: '.x-leaf'
});
With the previous stopPropogation
and the way suggested by @Brainfeeder, it finally works.