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

@bindable's defaultBindingMode property don't work. #73

Closed
andrevlins opened this issue May 13, 2015 · 6 comments
Closed

@bindable's defaultBindingMode property don't work. #73

andrevlins opened this issue May 13, 2015 · 6 comments
Assignees
Labels

Comments

@andrevlins
Copy link

If you specify a default binding mode in @bindable decorator It will not be used when you bind you attribute throught .bind.

<my-custom-element  my-attribute.bind="foo"></my-custom-element>

if my-attribute is defined as

@bindable({ name: 'myAttribute', attribute: 'my-attribute', defaultBindingMode: TWO_WAY})

foo will not be updated.... but if you use:

<my-custom-element  my-attribute.two-way="foo"></my-custom-element>

then foo will be updated as expected.

I'll make a repro on top of skeleton-nav later...

@jods4
Copy link
Contributor

jods4 commented Aug 11, 2015

The syntax has changed, now it's defaultBindingMode: bindingMode.twoWay but it is still not working...

@andrevlins
Copy link
Author

@jods4 you have to import import {bindingMode} from 'aurelia-framework';

@jods4
Copy link
Contributor

jods4 commented Aug 11, 2015

I know and I did (I am using TypeScript so that would have been an error otherwise). Does it work for you now?

I have a customAttribute with bindable properties, like so:

export class SomethingCustomAttribute {
  @bindable({ defaultBindingMode: bindingMode.twoWay })
  public x: string = null;
}

But when I use it so: <input something='{ x.bind = yada }' /> yada does not update but when I use it like this: <input something='{ x.two-way = yada }' /> it does.

@EisenbergEffect
Copy link
Contributor

Ok, I think this is a confusion about how to use custom attributes. A simple custom attribute that wants two-way binding to be the default should be declared like this:

@customAttribute('my-attr', bindingMode.twoWay)
export class MyAttr {
  valueChanged(newValue, oldValue) {
    //do stuff
  }
}

For simple attributes, you don't define the properties, the framework provides on automatically...and so the binding mode need to be declared on the class. You only declare it on properties if you have an attribute that maps to multiple properties (an options attr).

@jods4
Copy link
Contributor

jods4 commented Nov 9, 2015

@EisenbergEffect I am not sure I understand fully.

As my example shows, I'm trying to have an options attribute. I only used x in the example, but of course I actually have a bunch of attributes.

Something more like this (just an example, mind you):
<input auto-complete='src.one-time: suggestions, selected.bind: value' />

In this case selected.bind would not be two-way, even tough the field in the custom attribute is declared with @bindable({ defaultBindingMode: bindingMode.twoWay }) selected;.

@EisenbergEffect
Copy link
Contributor

Ok, I may have misunderstood. I'll re-open this and investigate further.

EisenbergEffect added a commit to aurelia/templating-binding that referenced this issue Dec 3, 2015
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

3 participants