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

EmptyPlaceHolder causes IndexOutOfBoundsException on MaterialListValueBox#getValue #751

Closed
jzaruba opened this issue Dec 10, 2017 · 5 comments
Assignees
Milestone

Comments

@jzaruba
Copy link
Contributor

jzaruba commented Dec 10, 2017

Selecting the very last item in the list and then calling MaterialListValueBox#getValue causes IndexOutOfBoundsException. This is because MaterialListValueBox#setEmptyPlaceHolder adds a new item into the list but does not add a new value into the array of the underlying model.

MaterialListValueBox#setEmptyPlaceHolder:

    public void setEmptyPlaceHolder(String value) {
        listBox.insertItem(value, 0);

        getOptionElement(0).setDisabled(true);
    }

I did not think this through at all, but maybe adding a null value at the 0-index of the underlying array could work? (Unless someone will beat me to it I shall look into it during this upcoming week.)

@jzaruba jzaruba changed the title emptyPlaceHolder causes IndexoutofBoundsException on MaterialListValueBox#getValue emptyPlaceHolder causes IndexOutOfBoundsException on MaterialListValueBox#getValue Dec 10, 2017
@kevzlou7979 kevzlou7979 self-assigned this Dec 11, 2017
@kevzlou7979 kevzlou7979 added this to the 2.0.1 milestone Dec 11, 2017
@kevzlou7979 kevzlou7979 changed the title emptyPlaceHolder causes IndexOutOfBoundsException on MaterialListValueBox#getValue EmptyPlaceHolder causes IndexOutOfBoundsException on MaterialListValueBox#getValue Dec 11, 2017
@jzaruba
Copy link
Contributor Author

jzaruba commented Dec 17, 2017

Are you working on this one? Otherwise I would make a fork. (I suppose release_2.0.1 would be the target branch...?)

Also it seems that calling MaterialListValueBox#clear probably annihilates the placeholder.

jzaruba pushed a commit to jzaruba/gwt-material that referenced this issue Dec 22, 2017
 - when a placeholder item is added as the very first item in the `#listBox` (`#setEmptyplaceHolder(String)`) a null value is added into the `#values` field, so their lengths match
 - public methods that dealt with item index are now made protected and called by their replacements that also add or subtract 1 (`#getIndexOffset()`) to reflect the offset caused by the extra (null) value representing the `#emptyPlaceHolder`;
 - added an `#emptyPlaceHolder` field, so the placeholder is preserved across clean() calls
@jzaruba
Copy link
Contributor Author

jzaruba commented Dec 22, 2017

A pull request has been created with a fix.

Anyways, maybe a more clear solution/approach to the #emptyPlaceHolder thing would be not adding the placeholder into the #listBox at all... It serves no purpose there, it can not be selected, it looks weird when the list is opened/expanded (especially with multiple=true when it has now a disabled checkbox)
...we could avoid the #values.length != #listBox.length thing.
Maybe the placeholder could be displayed only when the MaterialListValueBox widget is not opened/expanded...?

@kevzlou7979
Copy link
Contributor

@jzaruba Can you please add a test case for any new features to avoid regressions in the future.

@kevzlou7979 kevzlou7979 assigned jzaruba and unassigned kevzlou7979 Jan 4, 2018
@kevzlou7979
Copy link
Contributor

Maybe the placeholder could be displayed only when the MaterialListValueBox widget is not opened/expanded...?

I don't think its necessary to hide it.

@jzaruba
Copy link
Contributor Author

jzaruba commented Jan 4, 2018

@kevzlou7979 I did not consider this one a new feature, rather a bug-fix.
(If you referred to #753 then ignore this comment.)

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

No branches or pull requests

2 participants