Skip to content

[formControl] binding not working on Switch element #1624

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

Closed
chrillewoodz opened this issue Nov 21, 2018 · 1 comment
Closed

[formControl] binding not working on Switch element #1624

chrillewoodz opened this issue Nov 21, 2018 · 1 comment
Assignees

Comments

@chrillewoodz
Copy link

chrillewoodz commented Nov 21, 2018

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 4.2.4
  • Cross-platform modules: 4.2.1
  • Android Runtime: 4.2.0
  • iOS Runtime: 4.2.0
  • NativeScript-Angular: 6.1.0
  • Angular: 6.1.10

Describe the bug
Switch doesn't appear to support binding formControl to it as it doesn't set the default value of true, as well as it doesn't respond to changes to the value. It does however change the checked attribute.

I looked here and you said you had implemented this, although you only show an example with ngModel: #72

To Reproduce

Add the NativeScriptFormsModule and ReactiveFormsModule to AppModule:

@NgModule({
  imports: [
    NativeScriptModule,
    NativeScriptFormsModule,
    ReactiveFormsModule,
    AppRoutingModule
  ],
  exports: [
    NativeScriptModule
  ],
  declarations: [
    AppComponent
  ],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [NO_ERRORS_SCHEMA]
})

export class AppModule {}

Then create a form using FormBuilder:

public form = this.fb.group({
    ongoing: this.fb.group({
      checked: [true]
    })
  });

Then try to bind the formControl to the Switch:

<Switch class="ongoing" [formControl]="form.get('ongoing.checked')"></Switch>

You will see that the value is still false and if you listen to valueChanges it doesn't emit when you change the value.

Expected behavior
I expect the formControl value to be bound to the checked state when binding formControl to it.

@tsonevn tsonevn self-assigned this Nov 22, 2018
@tsonevn
Copy link
Contributor

tsonevn commented Nov 22, 2018

Duplicate of #1362

@tsonevn tsonevn marked this as a duplicate of #1362 Nov 22, 2018
@tsonevn tsonevn closed this as completed Nov 22, 2018
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

2 participants