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

Cannot preventDefault on (click) event on ion-checkbox #10309

Closed
jamesgroat opened this issue Feb 3, 2017 · 4 comments
Closed

Cannot preventDefault on (click) event on ion-checkbox #10309

jamesgroat opened this issue Feb 3, 2017 · 4 comments

Comments

@jamesgroat
Copy link
Contributor

jamesgroat commented Feb 3, 2017

Ionic version: (check one with "x")
[ ] 1.x
[x] 2.x

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:

The underlying _click fires first and sets checkbox._checked true or false regardless of (click) binding.

Expected behavior:

Ideally I could decide in code whether the click should result in checked or disabled state:

<ion-checkbox [checked]="selected" [disabled]="hidden" (click)="select(); $event.preventDefault();"></ion-checkbox>

Steps to reproduce:

<ion-checkbox (click)="$event.preventDefault();"></ion-checkbox> should prevent the underlying click from firing and not affect _checked state.

Other information:

Found underlying issue while testing fix for #9730 - @brandyscarney

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-201702031703
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.0.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.7.0
Xcode version: Not installed
@jgw96 jgw96 added the v2 label Feb 3, 2017
@rapropos
Copy link
Contributor

rapropos commented Feb 6, 2017

A potential workaround might be to bind to ionChange instead of click and use the technique described in this forum thread.

@Richie765
Copy link

Richie765 commented Feb 15, 2017

So for completeness, this is the workaround (using ionChange):

handleToggleChange(evt) {
  if(evt.checked !== myModel.checked) {
    // Don't toggle just yet, let it happen reactively
    evt.checked = myModel.checked;
    myModel.toggleChecked();
  }
}

Hope it will be fixed properly in Ionic though.

@jamesgroat
Copy link
Contributor Author

@Richie765 - thanks. I ended up doing something similar.

Also of note -- ion-toggle probably has the same issue.

@ionitron-bot
Copy link

ionitron-bot bot commented Mar 26, 2018

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Thank you for using Ionic!

@ionitron-bot ionitron-bot bot closed this as completed Mar 26, 2018
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Mar 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants