reactive
reactive copied to clipboard
Select.selectedIndex sends two updates
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
Is this issue specifically that Select.selectedIndex gets set twice every time?
yes
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?
@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.
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.