I have a couple weblinks of example places to trigger mouse clicks and keyboard entry.
When I try
document.getElementById("foobar").click()
in firefox console I get null error
I am trying to trigger inputs like at tiny. cc/oiclick
tiny. cc/oiclick1
tiny. cc/oiclick2
I cannot even get tab spacebar or enter to work since theres no event scan for 13 or 31 keypress
one solution is this tiny.cc/oiclick4
the element is named "null" in the inpector so i think this causes null error
Related
Gretting all.In TestCafe,there are pressKey()anddispatchevent()to use on press keyboard .I'm now struggling on one thing:I can't press the Numpad by neither pressKey() or dispatchevent().Here's what I've tried:
.dispatchEvent(#textbox,'keydown',{code:'numpad1'})
This actually fired,but it didn't type in the text 1 by the numpad1.Same thing on Digit1.Want to know if TestCafe support the different pressKey by Numpad and Digit?Thanks for reply.
Edit:
I tried to use dispatchevent() Here to fire Digit1 and numpad1,it works good,but if i tried on www.google.com,it fails.
Typing text via dispatching keyboard events is not allowed due to security reasons. See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Auto-repeat_handling_prior_to_Gecko_5.0. That's why the 'keydown' event is raised, but no value appears in the text box.
To simulate an input process with required key events, you can use the approach described here: https://stackoverflow.com/a/69917022/10684943.
Scenario: display alert message onblur (or onchange) as a part of javascript field validation.
User action with onblur:
1) click inside input
2) click outside the input
3) close the alert message
4) move mouse around
Result: mousedown seems to be performed at the position where you clicked out before the alert came up -- elements on the page get selected when you move the mouse around.
Note: This doesn't happen when tabbing out of the input.
Demo: http://jsfiddle.net/s9sc4/
<body>
Click inside the input and then outside of it.
<input type="text" onblur="alert('Close this alert message and move the mouse around.');" />
TEST TEST TEST
</body>
Reproduced on:
Firefox 28 and 29
Platforms: Windows 7 & 8 and OSX Mavericks (4 different machines).
Using a clean Firefox profile made no difference.
QUESTION:
Is this a bug, or default behavior? Chrome, Safari and IE don't behave like this.
If it's as designed, do I need to do something with preventDefault or cancel bubbling/stop propagation after the alert to stop this behavior?
You can try to add:
window.getSelection().removeAllRanges();
This will solve your issue.
To answer your question: this seems to be a bug of FireFox and needs a workaround. What happens is FireFox messed up the priority of events where focus is set first, prior to onblur. Browsers who don't have the bug will not fire the focus event when onblur occurs.
DEMO
That's interesting. This feels like a bug. I did get around it be calling setTimeout, and then calling alert:
<input ... onblur="setTimeout(function() { alert(...); }, 0);">
Scenario:
I have a RadCombobox and I have attached functions to most of the events.
One event of the combobox is OnClientBlur and I am using this to check whether value in Combo is "Unassigned" or not. If it is "Unassigned" I need to cancel the onblur event and keep the focus on to the same combo.
This is the javascript which I has been used to cancel the event.
if (sender.get_text() === "Unassigned") {
eventArgs.get_domEvent().preventDefault();
return false;
}
Problem:
When the user tabs out first time of the ComboBox the event gets cancelled and the focus stays on the same combo box (in this case it is the 3rd Combo).
But when the user hits the tab button again the focus moves to the next control.
When I debugged the code I found that when the user first hits the tab button, following line works
eventArgs.get_domEvent().preventDefault();
I can see the preventDefault function, see following snapshot.
but when the user hits the tab button again I get an error and cannot see preventDefault function, see following snapshot
I am not able to understand what is going wrong here. Anyhelp would be appreciated.
Your problem, revolves around the difference between MouseEvents and KeyEvents. And also the way Telerik implement the OnClientBlur event. As far as it doesn't point to a specific type of browser event, each time it gets triggered
As you see in the first snapshot you got clientX and clientY, which means your OnClientBlur derived from a MouseEvent.
Whereas in the second one you got altKey, altLeft, and also there is no button property, which means that this one is a KeyEvent.
The other point here is as you have these fields in the output:
e.bookmarks
e.behaviorPart
e.behaviorCookie
Means you are using one of the old versions of IE4+ to IE7 or IE8, which they have cancelBubble instead of preventDefault.
Sometimes events are not cancelable, and using event.cancelable you can make sure if the current event is cancelable or not.
At the end to fix you code you can simply do this:
if (sender.get_text() === "Unassigned") {
var domEvent = eventArgs.get_domEvent();
if(domEvent.cancelable){
if(typeof(domEvent.preventDefault)==="function")
domEvent.preventDefault();
else
domEvent.cancelBubble = true;
return false;
}
else{
//you can not cancel the event, do something else to make it manageable
}
}
I was going to implement response to keys, so I started off with:
window.addEventListener('keydown', function(e) {
alert(e.keyCode)
}, true)
It works with most keys. When I press a key it alerts the key code. (Of course, this is not the final design; just a test to see if it would work to make debugging easier.)
However, I found some interesting behavior. It does odd things when I use the space key.
When I press the space key, the alert with the number '32' (keycode of space) appears. However, when I release the key, the alert automatically closes!
I have found that with the Enter key, I have to press it again to close the alert. Not with space though.
Why is this?
Because space bar is used by the browser for closing alert messages (like enter).
explanation : The interesting behavior is that the browser use the space bar keyup to closing alerts, so you will see only the dialog beetween your keydown / keyup (in a case of the example when the space bar is not repeated)
You are triggering the alert on keydown, which means the keyup event, which the button of the alert probably listens to, happens when the alert is already there, effectively removing the alert immediately.
If you trigger the alert on keyup instead, this wont be an issue.
I am trying to create to popup div when pressing enter key, while the div contains a button (that I script to focus when it fired up) that will close the div when you press enter again. I receive the enter key from binding keypress and keydown, end up having different results.
Binding 'keypress'
Things work properly, with first enter key fires up a popup box and another enter key to dismiss the popup box.
Refer this JSFiddle.
Binding 'keydown'
This doesn't work correctly, as it fires up and dismiss the popup box immediately (which you won't see) with only one enter key.
Refer this JSFiddle.
My question is why would keydown generate odd behavior, it is like firing enter key twice for me, but the truth it wasn't. If I remove the button focus(), it will works correctly. That's puzzled me.
Tested with firefox and chrome.
You're rebinding the click event every single time the popup opens, so each time you click the close button it'll fire it multiple times which will cause unexpected behaviour.
Eg:
var Popup = function(){
$('#ok-button').live('click',function(){
$('#popup').remove();
});
};
This code means every time you create a new Popup instance, every single $('#ok-button') that exists will have another click event bound to it.
As for the reason why it immediately closes when you use keydown vs keypress, that's due to the fact that the moment the popup is opened you've set the focus to the button.
The two key events work differently (firing at slightly different times during the key process). It appears that with keydown, you're changing the focus in the middle of the actual action (pressing the button on the keyboard) which then continues and triggers the focused click.
Removing the focus stops the weird double trigger behaviour because you're no longer binding another click event.
I'd suggest changing your click event:
$('#ok-button').live('click', function(){
$('#popup').remove();
});
var Popup = function(){
// Whatever
};
I'd also suggest looking at jQuery's on event instead of using live.