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
Firefox - if.binds not working in repeat.for elements #250
Comments
You cannot place an if and a repeat on the same element. You need to nest them. You can nest them by using a template element. This is true of any attributes which are "template controllers" such as repeat, if and with. |
@EisenbergEffect Why does it work in chrome then? Is that also true for show.bind and any other bindable or just special cases like if.bind? if you cant use if/show.bind on the same element as the repeat.for how would one output a little of items and only display the ones that meet a specific criteria, without removing them from the list before hand? |
I have no clue why it works in Chrome. It shouldn't. If you want to use if and repeat together, you must nest them. Here's your code with the correct usage:
Any template controller can be used directly on an HTML element or on a Template element. |
Good to know, thanks for the info. The code above would still have empty li elements if the if.bind was false. Suppose show.bind could be applied to the li and the template if.bind would control the execution of the component instead the li Have a good one :) |
You could use a value converter to filter your list as well. Then you would only have li's for truthy values. |
True enough |
I just came across the same - all was working in Chrome and then I tested Firefox and IE. I've ended up doing the equivalent of:
Doing the |
@EisenbergEffect Can you elaborate more on why mixing template bindings shouldn't work? We're currently mixing |
There's a difference between whether you want to "if" a list in its entirely or "if" individual items in a list, which is why the order would matter in that case. However, I don't believe that all browsers preserve the ordering of the attributes. So, it could be that you want a particular order, but that the browser swaps those around at runtime. |
I just experienced this issue myself, including the inconsistency between Chrome and firefox(IE 11). Love Durandal and now love Aurelia |
@morioma Can you create a separate issue to let us track this? I believe we may have it handled through some new community tooling that "lints" templates, but I'd like to track it separately and make sure. |
Hmm, I'm confused about this, sorry - I have two cases where I'm combining repeat.for and if.bind, tr and option. If I use the nested template trick, I get empty elements, so that workaround doesn't seem to work? I could of course do a lot of pre-processing in the javascript model, but that would imho mean a big deficiency in Aurelia as this would mean a lot of boilerplate code, instead of self-explaining combination of two attributes. (Maybe if there's an easy way to use a value converter in template context, an example would be immensely helpful. :) |
Ok, to give a concrete example, my original line <option repeat.for="cl2 of task.classes" model.bind="cl2.id" if.bind="shownclass.id != cl2.id"> got replaced by <require from="./_filter"></require>
<option repeat.for="cl2 of task.classes | filterNE:'id':shownclass.id" model.bind="cl2.id">${cl2.name}</option> with _filter.js being export class FilterNEValueConverter {
toView(value, attr, other) {
return value.filter(e => e[attr] !== other);
}
} All if.binds containing inequalities, which are quite a common case I guess. I guess not as bad as I feared... :) Still, I'd consider this as a bug - the code is rather more convoluted and less maintainable than if Aurelia had a builtin for what I'd say is a first-class functionality (in my pretty simple app, I already had to replace three occurences of this - noticed only after testing in firefox). |
The |
@EisenbergEffect Hi, I am trying to use show.bind inside repeat.
This is not working.. |
@SalkiDixit Can you try with <div repeat.for="file of files">
<div class="file-type-icon">
<div show.bind="file.type === 'image'">This is image</div>
<div show.bind="file.type === 'video'">This is Video</div>
</div>
</div>
|
@bigopon Thanks..its working this way. |
@bigopon Hi,
I am trying to execute this piece of code. when i try to show video files, as per type only 'This is Video' should be shown, but Both are visible 'This is image' & 'This is video'. |
It should be like this <div repeat.for="file of files">
<div class="file-type-icon">
<div show.bind="file.type === 'image/jpeg' || file.type === 'image/png'">This is image</div>
<div show.bind="file.type === 'video/mp4'">This is Video</div>
</div>
</div> You missed |
Ran the below code in the navigation app with a simple list of strings to recreate. Basically the show.bind works, but if.bind does not. This is in firefox, but works fine in chrome.
The text was updated successfully, but these errors were encountered: