nativescript-checkbox
nativescript-checkbox copied to clipboard
Tap not working
Hi
I have the latest version of this plugin, also the NS 3.0+.
Now I can't call the tap method, only if I click the text.
The solution that I implemented is set the checkbox children of a Stack layout, and the parent with the tap event.
Have you tried the checkedChange
event instead?
How do I make it work? example: XML <CheckBox:CheckBox checkedChange="checkTap"/>
exports.checkTap = function(args) { console.log("TAP"); }
Hi again
The issue is present only in iOS. Also in iOS the alignment of checkbox is wrong.
I agree with author: tap event doesn't work on iOS if i click on checkbox. Can you help with this trouble?
Hi
An alternative solution is the CheckBox within the StackLayout:
<StackLayout width="50px" height="50px" tap="getCheckProp"> <CheckBox:CheckBox tap="getCheckProp" checkedChange="checkTap" checked="{{checkProp}}" id="myCheckbox" row="0" rowSpan="2" col="0" fillColor="red" loaded="thingSwitchLoaded"/> </StackLayout>
No, checkbox intercepts the tap event
The tap event not works, only if I check the event in one function:
var checkID = customControl.parent.parent.getViewById("myCheckbox"); var checkStatus = checkID.checked; if(checkStatus.toString() == "true") { }
But if it is within a list, the tap in a Layout.
Any update here ? I tried the workaround with StackLayout but it doesn't work.
In my case this helped me:
HTML
<CheckBox #elem [checked]="item.isChecked" class="checkbox" checkStyle="checkbox_yellow" (checkedChange)="elem.checked !== item.isChecked && toggleChecked(item)"></CheckBox>
TS public toggleChecked(item: LsItem) { item.isChecked = !item.isChecked; }
I mean about this line elem.checked !== item.isChecked
. I don't know but maybe it could help you @alexandruantonica in your case
Thanks @mrkorsar
The checkbox works but the main issue here is the event is not triggered.
Event checkedChange
doesn't work on iOS and as you can see in this file, the event is not supported.
The event works properly on Android.
Any Solution for this ?
I have a workaround for angular apps, using ngModel
and defining a setter
.
on .html: <CheckBox [(ngModel)]="selected"></CheckBox>
and on .ts: set selected(value: boolean) { this._selected = value; console.log('tap'); }
Can still reproduce this issue. any workarounds for NS core or NS + typescript?
Checkbox
extends Button
and overrides it's initNativeView
call. The core framework initiates tap handler in that method. Below override in your project should fix the issue.
import { CheckBox } from "nativescript-checkbox";
import { Button } from "tns-core-modules/ui/button";
(<any>CheckBox.prototype).originalinitNativeView = CheckBox.prototype.initNativeView;
CheckBox.prototype.initNativeView = function() {
Button.prototype.initNativeView.call(this);
(<any>CheckBox.prototype).originalinitNativeView.call(this);
};