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

Fix #8 - Dropdown not showing initial value when list is computed #7

Merged
merged 5 commits into from
Jul 17, 2017
Merged

Fix #8 - Dropdown not showing initial value when list is computed #7

merged 5 commits into from
Jul 17, 2017

Conversation

slawomir-brzezinski-at-interxion
Copy link
Contributor

@slawomir-brzezinski-at-interxion slawomir-brzezinski-at-interxion commented Dec 8, 2016

Hi @ssshake. Just found this issue in our project (see title).
See reproduction.

Cause: When the options list is a computed, the value binding will get assigned before the options computation adds any options. This loses that value, because the native select's .value setter will change it to '' when it can't find the option.

The original doesn't have the issue because templates are evaluated from leaves to roots.

See commit message of 'the fix commit' for details.

I've also added a solution to the remark I saw in #4, one that states that the PR 'Replaces a larger bug with a smaller one':
See commit message of the second small commit for details.

@slawomir-brzezinski-at-interxion
Copy link
Contributor Author

slawomir-brzezinski-at-interxion commented Dec 12, 2016

Hi @ssshake . I needed to add 1e8cad4, because the solution above causes a regression in data binding - the host path is no longer able to set or receive changes.
Here's the reproduction.
I'm least proud of the solution, but I really could not find any other way to fix the issue.

@slawomir-brzezinski-at-interxion slawomir-brzezinski-at-interxion changed the title Fix dropdown sometimes not showing the preselected value Fix #8 dropdown sometimes not showing the preselected value Dec 13, 2016
@slawomir-brzezinski-at-interxion slawomir-brzezinski-at-interxion changed the title Fix #8 dropdown sometimes not showing the preselected value Fix #8 - Dropdown not showing initial value when list is computed Dec 13, 2016
… list is computed

Cause: When the options list is a computed, the value will get assigned before it. This loses the value, because the native select's `.value` setter will change it to '' when it can't find the option (which is always the case here, because they haven't been assigned yet).

The original <select><template is=dom-repeat items=getAirportsForCity(city)></select> doesn't have the issue because templates are evaluated from leaves to roots.
…alue contains something and using like: `<select value={{val::change}}>)`

Occurs only when the options list is a computed, the value will get assigned before it, which loses the value, because the native select's .value setter will change it to '' when it can't find the option (which is always the case here, because they haven't been assigned yet).

Fixed by refactoring so that we never remove the static options in the optionsList observer (which seems right, because optionList only affects the dynamic options) and only update the visible selected option using the `.selected` property (which also takes care of #4).
…changed so that currently selected value becomes unavailable.

The problem is hinted in #4 (comment) and this commit introduces this sensible default.
It's a sensible default as otherwise user will be able to submit a value that according to UI logic is clearly not a valid one. The native select's `.value` accessor also resets to `''` when the value is not found, so is the natural choice.
This can be disabled by `keep-value-with-no-matching-option=true`
…select not receiving changes from the host path - needed to override the value property which also entailed a need to add artificial firing of the 'change' event :(
@leup
Copy link

leup commented Jul 13, 2017

I had this kind of issue on Safari where the drop down list was showing no selected value.
This PR solve my problem. Easy peasy, and thank you very very much @slawomir-brzezinski-at-interxion !

@ssshake ssshake merged commit c75def9 into vehikl:master Jul 17, 2017
@leup
Copy link

leup commented Jul 17, 2017

Thanks @ssshake

@slawomir-brzezinski-at-interxion
Copy link
Contributor Author

Thanks @ssshake. How about creating a release, so users have something to hook onto that isn't a hash?

@slawomir-brzezinski-at-interxion slawomir-brzezinski-at-interxion deleted the fix-sometimes-not-showing-initial-value branch July 17, 2017 17:04
@slawomir-brzezinski-at-interxion slawomir-brzezinski-at-interxion restored the fix-sometimes-not-showing-initial-value branch July 17, 2017 17:04
@leup
Copy link

leup commented Jul 17, 2017

That would be a good idea to add a new version tag yes, for bower for example.

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

Successfully merging this pull request may close these issues.

3 participants