Bug 74590 - [Forms] Selection change by type-ahead doesn't fire 'change' event
Summary: [Forms] Selection change by type-ahead doesn't fire 'change' event
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: yosin
URL: http://jsfiddle.net/SRyhK/
Keywords:
Depends on: 74700
Blocks:
  Show dependency treegraph
 
Reported: 2011-12-14 23:11 PST by Kent Tamura
Modified: 2011-12-21 23:18 PST (History)
5 users (show)

See Also:


Attachments
Patch 1 (4.58 KB, patch)
2011-12-15 20:26 PST, yosin
no flags Details | Formatted Diff | Diff
Patch 2 (4.74 KB, patch)
2011-12-15 21:00 PST, yosin
no flags Details | Formatted Diff | Diff
Patch 3 (4.73 KB, patch)
2011-12-15 21:33 PST, yosin
no flags Details | Formatted Diff | Diff
Patch 4 (4.34 KB, patch)
2011-12-15 21:57 PST, yosin
no flags Details | Formatted Diff | Diff
Patch 5 (4.27 KB, patch)
2011-12-15 22:05 PST, yosin
no flags Details | Formatted Diff | Diff
Patch 6 - Update failed test (4.82 KB, patch)
2011-12-15 22:53 PST, yosin
no flags Details | Formatted Diff | Diff
Patch 7 (6.80 KB, patch)
2011-12-19 19:23 PST, yosin
no flags Details | Formatted Diff | Diff
Patch 8 (7.08 KB, patch)
2011-12-20 17:40 PST, yosin
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kent Tamura 2011-12-14 23:11:33 PST
How to reproduce:
1. Open data:text/html,<script>c=0;</script><select autofocus onchange="c++;document.getElementById('console').innerHTML='onchange: '+c"><option>abc<option>def</select><div id=console></div>
2. Type 'd'.  The option 'def' is selected.

Expected:
3. 'onchange: 1' message is shown.

Actual:
3. Nothing happens.


This is very similar to Bug 74384.
Comment 1 yosin 2011-12-15 18:29:20 PST
Put HTML+SCRIPT into jsfiddle.net. See URL field.
Comment 2 yosin 2011-12-15 20:26:37 PST
Created attachment 119551 [details]
Patch 1
Comment 3 Kent Tamura 2011-12-15 20:44:40 PST
Comment on attachment 119551 [details]
Patch 1

View in context: https://bugs.webkit.org/attachment.cgi?id=119551&action=review

The code change looks ok.

> LayoutTests/fast/forms/select/menulist-type-ahead-find-expected.txt:1
> +WebKit Bug 74590

We should show what is tested.  The bug number is not useful.

> LayoutTests/fast/forms/select/menulist-type-ahead-find.html:16
> +function log(msg)
> +{
> +    var res = document.getElementById("log");
> +    res.innerHTML = res.innerHTML + msg + "<br>";
> +}
> +
> +function expectEq(expected, got)
> +{
> +    if (got == expected)
> +        log("PASSED got=[" + got + "]");
> +    else
> +        log("FAILED: expected[" + expected + "] got=[" + got + "]");
> +}

You don't need to make these function if you use ../../js/resources/js-test-pre.js.
or, they can be removed if we have <div id="res">FAIL</div> initially and recordIt() changes the content to 'PASS'.

> LayoutTests/fast/forms/select/menulist-type-ahead-find.html:21
> +function recordIt(ctrl)
> +{
> +   document.getElementById("res").innerText = ctrl.value;
> +}

I think recording the control value is not necessary.  .innerText = 'PASS' is enough.

> LayoutTests/fast/forms/select/menulist-type-ahead-find.html:37
> +    if (!window.layoutTestController)
> +        return;

It would be nice if we show a manual test instruction.
This test shows 'Type "c" To see "cherry"' for now. We had better explain the expected result too.
Comment 4 yosin 2011-12-15 21:00:45 PST
Created attachment 119552 [details]
Patch 2
Comment 5 Kent Tamura 2011-12-15 21:22:23 PST
Comment on attachment 119552 [details]
Patch 2

View in context: https://bugs.webkit.org/attachment.cgi?id=119552&action=review

> LayoutTests/fast/forms/select/menulist-type-ahead-find.html:30
> +    expectEq("apple", sel.value);
> +    eventSender.keyDown(ch);
> +    expectEq(expected, sel.value);

I think these expectEq() are unnecessary.  The type-ahead feature is tested in other test files.

> LayoutTests/fast/forms/select/menulist-type-ahead-find.html:31
> +    expectEq("PASS", res.innerText);

This is not needed.  The test result contains 'PASS' in "res" element.

> LayoutTests/fast/forms/select/menulist-type-ahead-find.html:45
> +<h1>WebKit Bug <a href="https://bugs.webkit.org/show_bug.cgi?id=74590">74590</a></h1>

Please show the purpose of the test.  The bug number is not useful.
Comment 6 yosin 2011-12-15 21:33:44 PST
Created attachment 119560 [details]
Patch 3
Comment 7 Kent Tamura 2011-12-15 21:48:04 PST
Comment on attachment 119560 [details]
Patch 3

View in context: https://bugs.webkit.org/attachment.cgi?id=119560&action=review

> LayoutTests/fast/forms/select/menulist-type-ahead-find.html:29
> +    expectEq("PASS", res.innerText);

I don't think this is needed. 'PASS' for this is already shown as a dump of <div id="res">
Comment 8 yosin 2011-12-15 21:57:56 PST
Created attachment 119564 [details]
Patch 4
Comment 9 Kent Tamura 2011-12-15 22:02:58 PST
Comment on attachment 119564 [details]
Patch 4

View in context: https://bugs.webkit.org/attachment.cgi?id=119564&action=review

> LayoutTests/fast/forms/select/menulist-type-ahead-find.html:13
> +    const sel = document.getElementById("sel");
> +    const res = document.getElementById("res");
> +    sel.focus();

Variable "res" is not needed.
You might want to remove "sel" too.
Comment 10 yosin 2011-12-15 22:05:22 PST
Created attachment 119566 [details]
Patch 5
Comment 11 Kent Tamura 2011-12-15 22:14:38 PST
Comment on attachment 119566 [details]
Patch 5

ok
Comment 12 WebKit Review Bot 2011-12-15 22:34:24 PST
Comment on attachment 119566 [details]
Patch 5

Attachment 119566 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/10903567

New failing tests:
fast/events/onchange-select-popup.html
Comment 13 yosin 2011-12-15 22:53:14 PST
Created attachment 119570 [details]
Patch 6 - Update failed test
Comment 14 Kent Tamura 2011-12-15 22:54:44 PST
Comment on attachment 119570 [details]
Patch 6 - Update failed test

ok
Comment 15 WebKit Review Bot 2011-12-16 01:08:16 PST
Comment on attachment 119570 [details]
Patch 6 - Update failed test

Clearing flags on attachment: 119570

Committed r103045: <http://trac.webkit.org/changeset/103045>
Comment 16 WebKit Review Bot 2011-12-16 01:08:21 PST
All reviewed patches have been landed.  Closing bug.
Comment 17 Csaba Osztrogonác 2011-12-16 02:42:58 PST
It made fast/forms/select-script-onchange.html fail on Qt - https://bugs.webkit.org/show_bug.cgi?id=74700
Comment 18 Hajime Morrita 2011-12-16 02:44:50 PST
Committed r103050: <http://trac.webkit.org/changeset/103050>
Comment 19 Csaba Osztrogonác 2011-12-16 02:46:49 PST
Reopen, because it was rolled out.
Comment 20 Hajime Morrita 2011-12-16 02:53:15 PST
Rolling out at http://trac.webkit.org/changeset/103050
due to a test failure on Chromium Windows:

- fast/forms/select-script-onchange.html

Result:
----
Test for http://bugs.webkit.org/show_bug.cgi?id=23721 Changing dropdown's selectedIndex within onchange handler fires another onchange.


FAILURE: onchange(2) called 2 times.

This select changes on focus: should not fire onchange.  
This select changes on change: should only fire onchange once.  
This select is changed by a timeout in the test script. It should not fire onchange.  
----
Comment 21 yosin 2011-12-18 20:58:33 PST
Hi Adam,

I would like to remove onchange event for Enter key for Windows because of this change makes type ahead fires onchange event and fix for BUG-74384 fires onchange for Up/Down key.

So, hitting Enter key fires additional onchange event. It seems Enter key behavior is introduced by
http://trac.webkit.org/changeset/16977

Is it OK to remove this Enter key behavior?

Thanks.
-yosi


Here is code for firing onchange:

HTMLSelectElement::menuListDefaultEventHandler

#if SPACE_OR_RETURN_POP_MENU
... GTK
#elif ARROW_KEYS_POP_MENU
... Mac
#else
        int listIndex = optionToListIndex(selectedIndex());
        if (keyCode == '\r') {
            // listIndex should already be selected, but this will fire the onchange handler.
            selectOption(listToOptionIndex(listIndex), DeselectOtherOptions | DispatchChangeEvent | UserDriven);
            handled = true;
        }
#endif
Comment 22 Adam Roben (:aroben) 2011-12-19 10:15:45 PST
Why is this a desirable change to make? (I'm not saying it's undesirable, just that no evidence is shown in favor of the change in this bug or the attached patches.) For instance, if the new behavior matches other browsers, that would be one reason it is a desirable change. This information should go in both the bug and your ChangeLog entry.
Comment 23 Kent Tamura 2011-12-19 17:52:13 PST
(In reply to comment #22)
> Why is this a desirable change to make? (I'm not saying it's undesirable, just that no evidence is shown in favor of the change in this bug or the attached patches.) For instance, if the new behavior matches other browsers, that would be one reason it is a desirable change. This information should go in both the bug and your ChangeLog entry.

We have some user-reported bugs. e.g.
  http://code.google.com/p/chromium/issues/detail?id=90447  Issue 90447: select onchange not working by cursor key selection

Cursor key selection and type-ahead selection change HTMLSelectElement::value, but don't dispatch 'change' events.  This behavior looks a bug for web developers, and IE and Opera fire 'change' events immediately in this case.
Comment 24 yosin 2011-12-19 19:23:00 PST
Created attachment 119973 [details]
Patch 7
Comment 25 Adam Roben (:aroben) 2011-12-20 07:18:08 PST
(In reply to comment #23)
> (In reply to comment #22)
> > Why is this a desirable change to make? (I'm not saying it's undesirable, just that no evidence is shown in favor of the change in this bug or the attached patches.) For instance, if the new behavior matches other browsers, that would be one reason it is a desirable change. This information should go in both the bug and your ChangeLog entry.
> 
> We have some user-reported bugs. e.g.
>   http://code.google.com/p/chromium/issues/detail?id=90447  Issue 90447: select onchange not working by cursor key selection
> 
> Cursor key selection and type-ahead selection change HTMLSelectElement::value, but don't dispatch 'change' events.  This behavior looks a bug for web developers, and IE and Opera fire 'change' events immediately in this case.

Thanks for the info. Knowing that IE, Opera, and Firefox (according to the Chromium bug) all have this behavior makes a strong case for WebKit having it, too!
Comment 26 Adam Roben (:aroben) 2011-12-20 07:19:24 PST
Comment on attachment 119973 [details]
Patch 7

View in context: https://bugs.webkit.org/attachment.cgi?id=119973&action=review

> Source/WebCore/ChangeLog:12
> +          and type ahead selection. So, onchange for Enter key is redundant. This behavior is 
> +          compatible to IE.

You should mention Firefox and Opera too, and version numbers if you know them.

> LayoutTests/fast/events/onchange-select-popup-expected.txt:9
>  blur event fired.
>  
> +PASS: change event fired.

This change isn't mentioned in your ChangeLog.
Comment 27 yosin 2011-12-20 17:40:10 PST
Created attachment 120123 [details]
Patch 8
Comment 28 Kent Tamura 2011-12-21 20:36:11 PST
Comment on attachment 120123 [details]
Patch 8

ok.
Comment 29 WebKit Review Bot 2011-12-21 23:18:07 PST
Comment on attachment 120123 [details]
Patch 8

Clearing flags on attachment: 120123

Committed r103497: <http://trac.webkit.org/changeset/103497>
Comment 30 WebKit Review Bot 2011-12-21 23:18:14 PST
All reviewed patches have been landed.  Closing bug.