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

Feature Request: Add support for linking to arbitrary DOM attributes and element content instead of just form element values. #5

Open
jamiemthomas opened this issue Oct 20, 2010 · 4 comments

Comments

@jamiemthomas
Copy link

Currently, the link() method (as documented and as functions) only supports linking to form input elements. While this is good for simple scenarios, it does not support rich applications that update automatically based on user input. Ideally you should be able to link to arbitrary attributes, such as the url of an IMG element, or the content of a SPAN element, and have these update as changes are made to the source javascript object.

@brq
Copy link

brq commented Oct 26, 2010

I wholeheartedly agree on both points. This is great; could be less restrictive. As it is, we still need to separately script the "linking" of an object with non-input elements and attributes.

@jamiemthomas
Copy link
Author

As it is, the link() API can be used with atttributes and elements through the use of a custom convertBack converter. The converter then takes the responsibility of setting attribute and element values when invoked. Both the value and the target DOM element is passed into the converter, so it is easy to to, just not obvious or succinct.

@ntziolis
Copy link

ntziolis commented Jan 4, 2011

Took me hours to figure out that currently only elements that are read and set by "val" are supported.
I actually then followed the suggestions with the convertBack converter but there are a couple of issues:
#1 You have to specify it for each mapping again, which leads to a lot of extra lines, rather than not having these lines at all
#2 The converter has to return an undefined value in order to stop the value from being set again by using 'val'

Instead of doing it this way I just added some logic that identifies the element type (tag) and uses the right field name based on that.
You can check it out here: ntziolis@5a8cade

@ntziolis
Copy link

ntziolis commented Jan 4, 2011

This only solves part of the problem however. As I have described in a comment in the code elements 'a' and 'img' do have multiple values that one would want to bind to like the link/image text as well as the href/src.
So it would be best if its possible to specify the actual attribute to link to. This would actually cover all use cases I can think of in this regard since this way its possible to specify exactly where the values are coming from as well as where they are supposed to go.
Of course this would have to be an optional mapping parameter so that the main interface is still simple. But I think this would be a welcome addition.
This way

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

No branches or pull requests

3 participants