ArcBees / gwtchosen

Port of the chosen javascript plugin for Google Web Toolkit
Other
107 stars 50 forks source link

ChosenChangeEvent fired only on selection (not deselection) #300

Open elmentecato opened 8 years ago

elmentecato commented 8 years ago

With ChosenListBox 3.1-SNAPSHOT in mobile mode (can replicate under latest desktop Chrome browser emulating iPhone 5 with DevTools), but have also seen the issue on an actual iPhone device (iphone 5s running iOS 9.2.1). I only get the ChosenChangeEvent when selecting a new option, but not when deselecting an existing selection. This works using large tablet or desktop mode (when the non-mobile UI is displayed).

Not only ChosenListBox is not reporting a deselection event, but if I call chosenListBox.getValues() after deselecting a selected value (when one was selected), it returns the value that I just deselected, so it never really removes it from its internal list, although the UI doesn't show that option as being selected anymore.

Additionally, if I select multiple options and I deselect them all before closing the dropdown, when I call chosenListBox.getValues(), I get all the options that were ever selected (but are not selected now).

I see no workaround for this issue right now (please let me know if you know of one). It's impossible for me to actually get the real list of selections when the user deselects any options in the process of selection.

elmentecato commented 8 years ago

Found workaround for this issue by calling update() every time a user has made selections.

chosenListBox.addHidingDropDownHandler(new HidingDropDownHandler()
    {
        @Override
        public void onHidingDropdown()
        {
            Timer timer = new Timer()
            {
                @Override
                public void run()
                {
                    chosenListBox.update();
                }
            };
            // have to schedule update in the future to avoid infinite update loop while popup is open
            timer.schedule(400);
        }
    });

chosenListBox.addUpdatedHandler(new UpdatedEvent.UpdatedHandler()
    {
        @Override
        public void onUpdated()
        {
            // Have to use scheduler if you want the values as soon as possible after
            //  an update because the UI/DOM can take its time to update the selections made by the user
            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand()
            {
                @Override
                public void execute()
                {
                    chosenListBox.getValues();
                    // Do something with the values above ...
                }
            });
        }
    });