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

Can't 2-way bind Array #463

Closed
steeleprice opened this issue Aug 22, 2013 · 6 comments
Closed

Can't 2-way bind Array #463

steeleprice opened this issue Aug 22, 2013 · 6 comments
Assignees
Labels
Milestone

Comments

@steeleprice
Copy link

Frequently I use a textbox for editing Tokenized Lists such as Tags.
It appears that there is a problem when passing an array to a mustache helper with a function.

Here is a fiddle demonstrating an error in live.js that prevents this.
http://jsfiddle.net/w4rdH/15/

What should happen here is:
The helper with a single value should bind to dummy element which works properly. (set to 'John')
The helper with an array value should bind to dummy2 element which is broken. (not set to 'Alex Bill')

In the AMD version, the error manifests differently and the result is that textbox value is set to the toString() value of the helper function.

I have tried to resolve this with several changes to the way the helper is constructed to no avail, nothing seems to accept an array if the return value is a function.

Any suggestions are welcome, this really appears to be a bug in live.js when constructing computes.

@bmomberger-reciprocity
Copy link
Contributor

Definitely there is a bug around returning functions from helpers here, but you can use can.view.hook() to enable two-way binding as you like. Here's your updated fiddle (and I fixed your helper too -- the 'value' property and the form element's value were mixed up): http://jsfiddle.net/air_hadoken/w4rdH/17/

@steeleprice
Copy link
Author

excellent workaround for this, I didn't think of using hook.
Thanks for the help!

@justinbmeyer
Copy link
Contributor

Did this get you on the right path? If it did, can you close the issue?

@steeleprice
Copy link
Author

No, it didn't, it works in a limited way on jsfiddle, but in real Apps, the helper is still failing (just differently). I will put more time into this, but it's still essentially a problem with arrays not being passed properly. I wouldn't say the work-around would have closed the issue anyway, it's not an intuitive solution and certainly not something you would expect to be a problem in a helper.

@ghost ghost assigned andykant Sep 27, 2013
@azazel75
Copy link

I have the same issue, but i can't understand what causes it

@azazel75
Copy link

This issue is hitting meu almost everywhere i have two-way helpers on Observe.List instances, for example a list of elements repeated for every Observe inside an Observe.List.
From my investigation the problem emerges on view.render.js at line 130 ( https://github.com/bitovi/canjs/blob/master/view/render.js#L130 ) while the code is evaluating the compute for the helper function ( which if executed will return the two way binding function, not a static piece of html).

After that line compute.hasDependencies >= 1 and in the end line 177 of the same file is executed, pushing an item in pendingHooks to execute live.attributes with arguments el, compute and the two way helper function which is not what live.attributes expects,IMHO.
Can someone more experienced than me have a look at the code please?

Thanks in advance

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

No branches or pull requests

6 participants