nstudio/nativescript-checkbox

checkedChange event is not working

Opened this issue · 3 comments

I am using typescript template and "checkedChange" event is not working on my xml page.

image

image

image

image

main-page.xml-->

<Page loaded="pageLoaded" class="page" xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:CheckBox="nativescript-checkbox">
    <Page.actionBar>
        <ActionBar title="My App" icon="" class="action-bar">
        </ActionBar>
    </Page.actionBar>
    <CheckBox:CheckBox checkedChange="{{ onCheckedChange }}" text="checkedChange event is not working" checked="false"/>
</Page>

main-view-model.ts-->

import { Observable } from 'data/observable';
import { ObservableProperty } from "../../common/observable-property-decorator";
import { Page } from 'ui/frame';

export class HelloWorldModel extends Observable {

  @ObservableProperty() textFieldValue: string = "";
  private _page:Page;

  constructor(page) {
    super();
    this._page=page;
  }
  onCheckedChange(){
      console.log("checked change");
  }
}

main-page.ts -->

import { EventData } from 'data/observable';
import { Page } from 'ui/page';
import { HelloWorldModel } from './main-view-model';

export function pageLoaded(args: EventData) {
  let page = args.object;
  page.bindingContext = new HelloWorldModel(page);
}

Got the same problem on Android (haven't tested on iOS yet). checkedChange does not fire while tap fires just fine.

XML:

<Page
    class="page"
    loaded="onPageLoaded"
    xmlns="http://schemas.nativescript.org/tns.xsd"
    xmlns:cb="nativescript-checkbox"
    >
...
<cb:CheckBox id="testbox" checked="false" text="Test checkbox" color="#777777" fillColor="#0e79b2" fontSize="30"  boxType="circle" loaded="onCheckboxLoaded" checkedChange="onCheckboxChanged"></cb:CheckBox>

NS v 4.2
tns-core-modules v 4.2.1
typescript v 3.1.3

Event should be in brackets

<CheckBox 
(checkedChange)="onChange($event)"
  checked="false"> 

checkedChange not firing in Javascript, but tap does. Have tried brackets around the event, but this causes a syntax error.

(checkedChange)="checkTap"