Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6326 (assigned defect)

Opened 2 years ago

Last modified 1 year ago

[PATCH] selectedIndex changes before the selection was made; breaks Form.Observer

Reported by: julik Assigned to: mislav (accepted)
Priority: high Milestone: 2.x
Component: Prototype Version: edge
Severity: critical Keywords: form value firefox opera hover select
Cc:

Description

There is an intrinsic problem with element value retrievals in Firefox. It seems that when the user is _hovering_ over a SELECT element (without selecting an option and closing the popup) the internal value of the select is changing as well. As a result, the observer registers the value change and fires the event before the user closes the popup or even explicitly selects the option.

Moreover, for reasons unknown Form.Observers also fires in Firefox after the page is loaded.

I don't know what the exact solution to the problem might be but this makes form observers basically useless in Firefox because all sorts of AJAX thingies happen before the user actually has chosen something. It seems that it would be much better to use onChange events instead of polling for the element value, or checking if the element is being mainpulated at the moment or not.

Alternatively this seems an item for the Bugzilla as well.

Attachments

selects.html (500 bytes) - added by julik on 10/01/06 22:47:36.
Edge case. Open the page and hovr above the select in Firefox to see the observer fire.
6326-hideous-hack.patch (2.0 kB) - added by kruse on 05/14/07 19:58:23.
Potential fix using "hideous hack"
6326-test.html (1.1 kB) - added by kruse on 05/14/07 20:00:11.
HTML to test "hideous hack". Works from "test" folder.

Change History

10/01/06 22:47:36 changed by julik

  • attachment selects.html added.

Edge case. Open the page and hovr above the select in Firefox to see the observer fire.

10/07/06 20:58:01 changed by mislav

  • cc set to mislav.
  • keywords changed from form value firefox to form value firefox opera hover select.
  • severity changed from major to critical.

Oh my. This is nasty - extremely nasty. It even gets worse in Opera 8.5. Thank you, Julik, for a quick-n-simple test case. It's obvious this cannot be covered with unit tests :(

I don't think this is a bug, I think it's by design and that Firefox and Opera developers never did think the value will matter while the user is choosing from the select box. But it matters. Definitely report it to Bugzilla to see the reaction (post link here afterwards).

I propose a workaround - to hook into onChange (as Julik suggested) for elements. I don't know what about whole forms, though.

10/07/06 21:51:31 changed by mislav

  • summary changed from Form value retrieval picks up the new value in Firefox before the onChange event is actually fired to Selectbox value changes when only hovering (breaks polling).

Forms have onChange, too! Good stuff.

OK, I now understand why the polling. The onChange event doesn't trigger until the input box (or textarea) loses focus.

So polling is required for textboxes/areas, but doesn't work for selectboxes - for which onChange works quite well. Do I smell some conditional branches?

10/08/06 22:25:30 changed by julik

Thx for the tip, but onchange for FORM elements works only in Safari and Firefox and is not part of the W3C spec, i.e. it's substandard. I can somewhat imagine the reasoning for changing the value of the select when hovering (akin to changing the value of an input field when entering text) but I consider it totally unintuitive.

This is clearly a setback for Gecko only.

10/08/06 22:55:08 changed by julik

Well, Mozilla folks are on for https://bugzilla.mozilla.org/show_bug.cgi?id=307339 but knowing the bugzilla triage it's going to take ages before they decide on the behavior. The bug is open for a year.

Rails might adopt onChange and stash the select value somewhere on the element, but this might conflict with user's events.

10/08/06 22:55:47 changed by julik

  • summary changed from Selectbox value changes when only hovering (breaks polling) to Mozillas change selectedIndex before the selection was made (breaks Form.Observer).

10/09/06 07:23:21 changed by mislav

I don't like the new title. It isn't only about Mozilla, I already confirmed the behavior in Opera, too.

That aside, let's get back to the real problem. A hideous hack comes to mind - creating a mirror property _selectedIndex for SELECTs that reflects real selectedIndex but only onChange.

05/14/07 19:58:23 changed by kruse

  • attachment 6326-hideous-hack.patch added.

Potential fix using "hideous hack"

05/14/07 20:00:11 changed by kruse

  • attachment 6326-test.html added.

HTML to test "hideous hack". Works from "test" folder.

05/14/07 20:06:10 changed by kruse

  • summary changed from Mozillas change selectedIndex before the selection was made (breaks Form.Observer) to [PATCH] Mozillas change selectedIndex before the selection was made (breaks Form.Observer).

I added a patch file that implements the "hideous hack" suggested by mislav. This solution only affects Form.Observer and Form.Element.Observer. Another possibility would be to change Form.Element.getValue, but that's a lot more intrusive.

Do not that a side-effect of said Hideous Hack is that the observers are not notified in Mozilla when the user changes the select value using the up/down keys, because onChange doesn't fire in Mozilla until the element loses focus or the select drop-down is closed.

05/14/07 20:19:21 changed by mislav

  • cc deleted.
  • owner changed from sam to mislav.
  • status changed from new to assigned.
  • summary changed from [PATCH] Mozillas change selectedIndex before the selection was made (breaks Form.Observer) to [PATCH] selectedIndex changes before the selection was made; breaks Form.Observer.

Ugh, it's hideous! :)

Thanks, I'll try it out in my next iteration of form patches.