Dynamic Select empty when opening second time. #5935

Closed
AdoWebDesig opened this Issue Apr 25, 2013 · 6 comments

Projects

None yet

3 participants

@AdoWebDesig

Hi,

When opening select(dromdown) for secod time, the list is empy. This happens only if the list does not fit on the screen:

http://jsfiddle.net/nzHxZ/1/

  1. Click on Go to
  2. open both dropdowns
  3. go back to home
  4. Do again step 1 to 3

You wil see that big dropdown is empty when opening second time.

@jaspermdegroot
Member

@AdoWebDesig

Thank for reporting the issue. This is indeed a bug.

@jaspermdegroot
Member

Cleaned up the test page (missing body tag, don't append a select to a ul, use latest code): http://jsbin.com/owasir/23/edit

@vstars
vstars commented Apr 26, 2013

I removed the old dialog page of select if it exits in the build function of widget. The select can be opened for second time.
http://jsbin.com/amuzad/1/edit/

@AdoWebDesig

Thx guys!

@uGoMobi,

One question. Do I always have to use pageinit when adding events like click ets?

@jaspermdegroot
Member

@AdoWebDesig

I strongly recommend to always bind to pageinit, instead of $(handler) or $(document).ready(handler). There are situations where it doesn't make a difference, but better make a habit of it.

As @vstars pointed out, the problem here is indeed the selectmenu dialog page that remains in the DOM, only the list is removed from the dialog.

The dialog that is created gets the same ID as your select with the "-dialog" suffix. You create a new select with the same ID each time the button on the homepage is clicked. The framework doesn't create a new dialog a second time because there is already a dialog with that ID. If you don't give the select an ID, the dialog gets a random ID uuid-[random number]-dialog and the problem is gone: http://jsbin.com/owasir/28/edit

However, this way you can end up with many dialogs in the DOM which is not good. So a better workaround is to remove the dialog with custom code. See: http://jsbin.com/owasir/29/edit

@AdoWebDesig

Thank you very much.

@gabrielschulhof gabrielschulhof added a commit that closed this issue May 2, 2013
@gabrielschulhof gabrielschulhof Custom select: Remove dialog upon _destroy. Fixes #5935 - Dynamic Sel…
…ect empty when opening second time.
afabf5b
@gabrielschulhof gabrielschulhof added a commit that referenced this issue May 2, 2013
@gabrielschulhof gabrielschulhof Custom select: Remove dialog upon _destroy. Fixes #5935 - Dynamic Sel…
…ect empty when opening second time.

(cherry picked from commit afabf5b)
2e55b22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment