Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Select.selectedIndex sends two updates #38

Open
fmpwizard opened this issue Sep 26, 2011 · 5 comments
Open

Select.selectedIndex sends two updates #38

fmpwizard opened this issue Sep 26, 2011 · 5 comments
Labels
Milestone

Comments

@fmpwizard
Copy link

Hi,

If you go to the demo site here:
http://reactive-web.tk/html/Select
click on the "live demo" button at the bottom of the page.

Open Firebug, and go to the Net tab

Then select Linux from the OS list, after a few seconds you will see a
few request being made, click on the POST request that is about 393B
in size, and you will notice that some of the javascript that is
executed is duplicated,

for example, I see:
try{document.getElementById('vowel').selectedIndex=0}catch(e){}
try{document.getElementById('vowel').selectedIndex=0}catch(e){}

Thanks

Diego

@nafg
Copy link
Owner

nafg commented Nov 11, 2011

Is this issue specifically that Select.selectedIndex gets set twice every time?

@fmpwizard
Copy link
Author

yes

@psiska
Copy link

psiska commented Jun 22, 2012

I think you are referring to http://www.reactive-web.co.cc/showdemo/SelectDemo

In that case two events are fired because "select" contains onclick and onchange handler.
When you click the "select" onclick handler fires 1. post request. After that you click Linux - the onchange handler fires the 2. post request (with 393B of data) and 3. request is being firef again by onclick handler.

The solution would be remove the onclick handler.

Or are you suggesting that the 3. request should be called, because there was no change?

@nafg
Copy link
Owner

nafg commented Jun 24, 2012

@sisken -- that's not the issue being discussed. The onclick ajax request (3) returns empty. However if you look at the javascript returned by the onchange handler, it contains:

reactive.updateProperty('variant','selectedIndex',0)
reactive.updateProperty('variant','selectedIndex',0)
reactive.updateProperty('consonant','selectedIndex',0)
reactive.updateProperty('consonant','selectedIndex',0)
reactive.replaceAll('feedback',"You selected B and I")
reactive.updateProperty('consonant','selectedIndex',0)
reactive.updateProperty('consonant','selectedIndex',0)
reactive.replaceAll('feedback',"You selected B and I")
...

Notice every select has its selectedIndex set twice.

@psiska
Copy link

psiska commented Jun 26, 2012

I see.
If I understand it properly, each time you update PropertyVar - in this case selectedIndex - new javascript snippet is queued to be pushed to client.

It seems like onchange event the selectedIndex is updated. However this triggers selectedItem Select.scala L96 which then triggers selectedIndex once again Select.scala L92 and again is selectedIndex on line 96 updated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants