aurelia / templating-resources

A standard set of behaviors, converters and other resources for use with the Aurelia templating library.
MIT License
59 stars 55 forks source link

matcher.bind does not work inside of repeat with checkboxes #388

Closed pkozul closed 5 years ago

pkozul commented 5 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: The matcher does not work inside of repeat.for when using checkboxes and arrays of objects.

The example below (from the Aurelia docs) does work, as the matcher gets called, but it doesn't use repeat.for.

https://aurelia.io/docs/binding/checkboxes#array-of-objects-with-matcher

If you remove the three checkboxes in the example above, and replace them with a repeat.for, the matcher no longer gets called.

Expected/desired behavior: Demo: https://codesandbox.io/s/objects-s7lec?fontsize=14&module=%2Fsrc%2Fapp.ts

The call to console.log() in the above demo shows that the matcher never gets called. Also,ticking the checkboxes results in duplicates being added to the selected list.

bigopon commented 5 years ago

I think Codesandbox has some issues with dependencies, as you can see from this example: https://codesandbox.io/s/httpsgithubcomaureliatemplating-resourcesissues388-ftszo

It comes with latest version of templating-resources, and is working fine.

Can you make sure your project has latest version of this module and try again?

pkozul commented 5 years ago

As you said, it does now work in Codesandbox, but I cannot get it to work on my machine. I have created a brand new Aurelia project using the latest aurelia-cli and then updated to the latest version of this module:

npm install aurelia-templating-resources@latest

It does not work though. The matcher never gets called. Is there another Aurelia library that also needs to be updated for this to work? Can you try creating a new Aurelia project to see if you get the same behaviour?

Thanks.

bigopon commented 5 years ago

@pkozul Sorry for the false information. Can you try the following in your app entry (probably main.ts):

import {Repeat} from 'aurelia-templating-resources';

Repeat.useInnerMatcher = false;

The reason is without static field useInnerMatcher, it would have been a breaking changes. So we made it an opt-in fix.

pkozul commented 5 years ago

@bigopon Yes, that did the trick! Now works. Thank you.

I see it's documented in the Aurelia docs, but I would never have found it myself :-)

https://aurelia.io/docs/api/templating-resources/class/Repeat/property/useInnerMatcher/