Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Dynamic Select empty when opening second time. #5935

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

Dynamic Select empty when opening second time. #5935

AdoWebDesig opened this issue Apr 25, 2013 · 6 comments

Comments

@AdoWebDesig
Copy link

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
Copy link
Contributor

@AdoWebDesig

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

@jaspermdegroot
Copy link
Contributor

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
Copy link

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
Copy link
Author

Thx guys!

@uGoMobi,

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

@jaspermdegroot
Copy link
Contributor

@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
Copy link
Author

Thank you very much.

gabrielschulhof pushed a commit that referenced this issue May 2, 2013
…ect empty when opening second time.

(cherry picked from commit afabf5b)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants