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

Checkbox is not checked using value attribute #45

Closed
cschroeter opened this issue Jul 14, 2016 · 4 comments
Closed

Checkbox is not checked using value attribute #45

cschroeter opened this issue Jul 14, 2016 · 4 comments
Labels
Milestone

Comments

@cschroeter
Copy link

cschroeter commented Jul 14, 2016

import { Component } from '@angular/core';
import { PolymerElement } from '@vaadin/angular2-polymer';

@Component({
  moduleId: module.id,
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css'],
  directives: [
    PolymerElement('paper-checkbox'),
    PolymerElement('paper-button'),
  ]
})
export class AppComponent {

  public test: boolean = true;

}
<p>
  Value of test: {{test}}
  <paper-checkbox [(value)]="test">Template</paper-checkbox>
</p>

bildschirmfoto 2016-07-15 um 00 26 20

@tallaxes
Copy link
Collaborator

tallaxes commented Jul 15, 2016

Should be checked instead of value:

<p>
  Value of test: {{test}}
  <paper-checkbox [(checked)]="test">Template</paper-checkbox>
</p>

@cschroeter
Copy link
Author

cschroeter commented Jul 15, 2016

That does the trick but then you still can not use the ngControl directive for model driven forms

<p>{{form.value | json}}</p>

<form [ngFormModel]="form">
  <paper-input label="Name" ngControl="name" error-message="Max 10 chars"></paper-input>
  <paper-checkbox ngControl="classic">Classic</paper-checkbox>
</form>
import { Component } from '@angular/core';
import { ControlGroup, FormBuilder, Validators } from '@angular/common';
import { PolymerElement } from '@vaadin/angular2-polymer';

@Component({
  moduleId: module.id,
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css'],
  directives: [
    PolymerElement('paper-button'),
    PolymerElement('paper-checkbox'),
    PolymerElement('paper-input'),
  ]
})
export class AppComponent {

  private form: ControlGroup;

  private car = {
    name: '',
    classic: true
  };

  constructor(private fb: FormBuilder) {
  }

  public ngOnInit(): void {
    this.form = this.fb.group({
      name: [this.car.name, Validators.maxLength(10)],
      classic: [this.car.classic]
    });
  }

}

@Saulis
Copy link
Contributor

Saulis commented Jul 29, 2016

Added a feature to target ngControl to use checked instead of value property for elements which extend IronCheckedElementBehavior

@platosha
Copy link
Owner

Fixed in #62

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

7 participants