reactive icon indicating copy to clipboard operation
reactive copied to clipboard

Select.selectedIndex sends two updates

Open fmpwizard opened this issue 13 years ago • 5 comments

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

fmpwizard avatar Sep 26 '11 02:09 fmpwizard

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

nafg avatar Nov 11 '11 05:11 nafg

yes

fmpwizard avatar Nov 11 '11 12:11 fmpwizard

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?

psiska avatar Jun 22 '12 13:06 psiska

@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.

nafg avatar Jun 24 '12 19:06 nafg

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.

psiska avatar Jun 26 '12 07:06 psiska