-
Notifications
You must be signed in to change notification settings - Fork 53
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
md-select: initial selected value is not selected #292
Comments
@tdamir I'm not sure if I got this right. What does this mean:
What's the hidden select element? 😃 Does this work with a native select? |
Oh, now I understand what you mean with the hidden select. It's the native element which is wrapped by Materialize, right? |
This works: https://gist.run/?id=598658b48d36328f52bd406c986ff6a6 view: <template>
<select md-select="label: Label" value.two-way="model.value">
<option repeat.for="item of model.items" model.bind="item">${item.name}</option>
</select>
<div>
selected: ${model.value.id}
</div>
</template> view model: export class App {
items = [
{ id: 0, name: 'Option A' },
{ id: 1, name: 'Option B' },
{ id: 2, name: 'Option C' },
{ id: 3, name: 'Option D' }
];
model = {
items: this.items,
value: this.items[1]
};
} |
According to this hub entry, There's another description which describes how to use a matcher function. You could use the id there if you really need to match by id. |
I apologize for the confusion. Correct, I was referring to the native element by hidden select. The following is working as expected on native elements in all browsers. If you run this on Chrome the wrapper will also select the option but on Edge, IE and FF only native element is selecting correctly the option (according to the DOM inspector).
|
According to the doc the sample should work because we are working with numbers: |
I've copied your code into a gist and called it in Firefox 49: It seems to work there. The gist displays "selected: 2" and "Option C" is selected when I run it. I don't have access to Edge here and IE11 won't run gist.run. I'll try this in Edge when I get home. And of course you're right with binding to numbers. I've overlooked that, sorry. 😃 |
I tried your code on FF (49) and it works. My colleague said that on FF sometimes it works and sometimes not. He is not sure about FF version. He will try the sample at home. On Edge it is not working for sure because I tried it. |
That would be great, indeed. That way I may actually be able to find a reason for that. 😉 Did I get this right that this is only an issue when binding to a number? So our "food" example in the catalog app will work? I'd like to know because I think in that case we should add an example which binds to an index. |
I tried the food sample and option in the native element is selected (if initially set) but wrapper is not showing it on IE11 and Edge. As for the FF we figured out that it didn't worked because id was a number and selectedValue was a string (in our project) and in that case aurelia cannot match the element (probably they are using === for equality). So it looks like there are only issues with IE and Edge, |
Okay, thanks for the additional info! 😃 |
The difference between Chrome and Edge is: at the time the component is created, Chrome has The value of I couldn't really track this down further but I guess the I'm not sure how to approach this now but I'll try further. 😃 |
Seems to be fixed when wrapping the initialization in a |
Released in 0.17.1. |
@tdamir About Firefox: I guess the reason why it sometimes works and sometimes doesn't is there's something running asynchronously. That should be gone with this change since the taskQueue runs at specific points in time after microtasks are finished. Please try it with this change in Firefox. If it still happens, we can reopen this issue. |
@Thanood I think the Firefox issue was because of our code but I'll let you know if the issue persist. |
This works well on Chrome but on FF, Edge and IE11 the selected option is not selected. If I display the hidden select element, the option is selected.
If I bind to selected attribute then the selected option will be selected on the first render on all browsers:
The text was updated successfully, but these errors were encountered: