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

ChosenValueListBox allowSingleDeselect not working as expected #285

Open
schragmanuel opened this issue Oct 22, 2015 · 17 comments
Open

ChosenValueListBox allowSingleDeselect not working as expected #285

schragmanuel opened this issue Oct 22, 2015 · 17 comments
Labels

Comments

@schragmanuel
Copy link

I use ChosenValueListBox to dynamically fill a ListBox with Objects at runtime (setAcceptableValues). When i set the option setAllowSingleDeselect(true), I expect the little cross icon to appear as mentioned in the allowSingleDeselect example on http://dev.arcbees.com/gwtchosen/. Of course, I set the first element in the acceptable values to null, because this is needed as stated in the docs and the line of Code in ChosenImpl:

allowSingleDeselect =
            options.isAllowSingleDeselect() && optionsList.getLength() > 0
                    && "".equals(optionsList.getItem(0).getText());

I managed to work around this issue by setting a list with a null value on creation of the ChosenValueListBox. But this only works for the first time the box is attached to the DOM. When I switch between Views, which are singletons, the cross disappears.

No idea if it's related, but when debugging I can see that after a setAcceptableValues() with a null Element, the empty Element first appears in the DOM, but after the method updateChosenListBox() it's gone.

public void setAcceptableValues(Collection<T> acceptableValues) {
    values.clear();
    valueKeyToIndex.clear();
    ChosenListBox listBox = getChosenListBox();
    listBox.clear(false);

    for (T nextNewValue : acceptableValues) {
        doAddValue(nextNewValue);
    }

>>>>updateChosenListBox();
}
@olafleur
Copy link
Member

Are you using version 3.0.1 that we just released?

@schragmanuel
Copy link
Author

No, we had the problem on version 3.0 and I switched to 3.1-SNAPSHOT to see if the problem has been solved. You think it's worth a try with 3.0.1 anyway?

@meriouma
Copy link
Member

No, they are the same at the moment. Can you post your Renderer's code? FYI, the dev-site samples are using version 3.1-SNAPSHOT

@schragmanuel
Copy link
Author

Here it is:

public final class BreedRenderer extends AbstractRenderer<BreedDto> {

    @Override
    public String render(BreedDto item) {
        if (item != null) {
                return item.getId() + " - " + item.getNameDe();
        } else {
            return "";
        }
    }
}

@meriouma
Copy link
Member

Just to be sure, what is not working exactly? I'm not sure what's the issue and what is not working as expected

@schragmanuel
Copy link
Author

Ok. I try to explain it again in other words:

Here is the declaration of my chosen box with custom filtering:

ChosenOptions opt = new ChosenOptions();
opt.setResultFilter(personSearchProvider);
opt.setAllowSingleDeselect(true);
businessField = new ChosenValueListBox<>(new AddressSearchResultPersonRenderer(), opt);
personSearchProvider.setBox(businessField);

The Renderer returns "" for a null object.

This is the relevant extract from personSearchProvider which implements ResultsFilter:

public class PersonSearchProvider implements ResultsFilter {

private ChosenValueListBox<SearchResultAddressDto> box;

@Override
public void filter(String searchText, final ChosenImpl chosen, boolean isShowing) {
    if (!isShowing) {
        return;
    }
    addressRestClient.search(searchText, MAX_RESULTS, true, new AbstractMethodCallback<List<SearchResultAddressDto>>() {

        @Override
        public void onSuccess(Method method, List<SearchResultAddressDto> response) {
            if(box != null) {
                response.add(0, null); // Adding null item to allow ChosenBox to display the clear button
                box.setAcceptableValues(response);
            }
        }
    });
}
}

As you can see, a null item is inserted at position 0.

I would expect:

  • to see an html tag in the DOM at position 0 of the corresponding element the clear button to show up as soon as an item is selected, because the JavaDoc says: With ChosenValueListBox, if you want to display the placeHolder message or be able to reset the component by passing null. You have to pass null as first element of your collections Thank you for taking a look at this. I hope it is clearer now.

@meriouma
Copy link
Member

What browser/version are you using? Can you confirm the you can select and deselect elements in the samples?

@schragmanuel
Copy link
Author

I'm using Chrome Version 46. And yes, I confirm that the sample under "allowSingleDeselect" is working. Also the other examples do work well.
But the samples are all using ChosenListBox whereas we're using ChosenValueListBox.

@meriouma
Copy link
Member

Sorry, I meant this page : http://dev.arcbees.com/gwtchosen/widgetsample/, but the ChostValueListBox sample doesn't have a placeholder. It's still unclear to me what's wrong on your side

@meriouma
Copy link
Member

I've done a simple test and it's working as expected. setting allowSingleDeselect to true and having null as first acceptable values allows to deselect an element

@schragmanuel
Copy link
Author

  1. On the link you provided, deselect with x icon works for the Simple ChosenListBox example but x doesn't show up in the Value List box example (Tested with Chrome and Firefox). Does this really work for you?

  2. In your example, do you do asynchronous filtering as I described in the comment above?

  3. In my ui.xml the element looks like this:

    <chsn:ChosenValueListBox ui:field="businessField" />

  4. The renderer needs to return "" (empty string) for a null element right?

  5. Can you provide the code of your example?

Thank you

@schragmanuel
Copy link
Author

Sorry, do you have any news on this? Thank you

@meriouma
Copy link
Member

Without a more complete code example, it'll be hard for us to give more feedback. We tried to reproduce your issue but were unable to..

schragmanuel pushed a commit to schragmanuel/gwtchosen that referenced this issue Nov 23, 2015
@schragmanuel
Copy link
Author

I made a fork and could reproduce the issue. These are the changes: schragmanuel@19087ad

Can you please try again and give me a feedback? Thank you

@meriouma
Copy link
Member

Thanks for the complete example. I'll try to look at this soon

@olafleur olafleur added the bug label Jan 4, 2016
@paleface74
Copy link

Why aren't I on there

olafleur pushed a commit that referenced this issue Mar 3, 2016
Fix for #285 : ChosenValueListBox allowSingleDeselect not working as expected
@okorokhina
Copy link

Fellows, getting same problem with 3.0.. Please say where you've merged it and in what version this bug is gone. Thank you!

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

No branches or pull requests

5 participants