Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChosenChangeEvent fired only on selection (not deselection) #300

Open
elmentecato opened this issue Mar 21, 2016 · 1 comment
Open

ChosenChangeEvent fired only on selection (not deselection) #300

elmentecato opened this issue Mar 21, 2016 · 1 comment

Comments

@elmentecato
Copy link

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

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 ...
                }
            });
        }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant