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

Comments

Projects
None yet
6 participants
@steeleprice

steeleprice commented Aug 22, 2013

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

This comment has been minimized.

Show comment
Hide comment
@bmomberger-reciprocity

bmomberger-reciprocity Sep 10, 2013

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/

Contributor

bmomberger-reciprocity commented Sep 10, 2013

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

This comment has been minimized.

Show comment
Hide comment
@steeleprice

steeleprice Sep 10, 2013

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

steeleprice commented Sep 10, 2013

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

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Sep 15, 2013

Contributor

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

Contributor

justinbmeyer commented Sep 15, 2013

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

@steeleprice

This comment has been minimized.

Show comment
Hide comment
@steeleprice

steeleprice Sep 19, 2013

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.

steeleprice commented Sep 19, 2013

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

This comment has been minimized.

Show comment
Hide comment
@azazel75

azazel75 Sep 29, 2013

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

azazel75 commented Sep 29, 2013

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

@azazel75

This comment has been minimized.

Show comment
Hide comment
@azazel75

azazel75 Sep 29, 2013

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

azazel75 commented Sep 29, 2013

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