Open Bug 1035914 Opened 10 years ago Updated 2 years ago

Confirm alert with enter trigger event on page

Categories

(Core :: General, defect)

30 Branch
x86_64
Linux
defect

Tracking

()

UNCONFIRMED

People

(Reporter: richard.petersen, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/34.0.1847.116 Chrome/34.0.1847.116 Safari/537.36

Steps to reproduce:

1) Create page, which has an textfield (input) listening to the keyUp event (the event is appended with jQuery). 
2) When pressing enter while focusing the textfield, an alert is called. 
3) Press enter for confirming the alert. 


Actual results:

3) The alert shows up again, after pressing enter. But it does not opens again when clicking on 'ok'. 


Expected results:

3) The alert should only be shown once.
I can confirm this with this test case:

    <html>
    <head>
    <script type="text/javascript">
    
    function process_textbox(options)
    {
    	var evt = options.evt
    	if(evt.keyCode == 13)
    	{
    		if(!confirm('Are you sure?'))
    		{
    			return false
    		}
    		else
    		{
    			console.log('yay')
    		}
    	}
    }
    
    function pageload()
    {
    	document.getElementById('t1').addEventListener('keyup', function(evt){process_textbox({evt:evt})}, false)
    }
    
    window.addEventListener('load', function(){pageload()}, false)
    </script>
    </head>
    <body>
    <input id="t1">
    </body>
    </html>

If I type something and hit enter it will open a confirm dialog. I'd like to be able to hit enter again to select "ok" and continue.

In Chrome, this works. I can just hit enter to confirm the dialog box with "Ok" and it work fine. However, in Firefox it will detect the the enter on the dialog box as another enter in the text box and call the listening function again. It seems that maybe the focus is not moving from the textbox to the dialog box? This creates an infinite loop. The only way to break out is to click the "Ok" button instead of hitting enter on it.
BTW, my comment above was for FF 47.0.1.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.