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

Ion-checkbox sends ionChange event when scrolling with Virtutal Scroll #12126

Closed
JacobT14 opened this issue Jun 21, 2017 · 2 comments
Closed

Comments

@JacobT14
Copy link

Ionic version: (check one with "x")
[ ] 1.x (For Ionic 1.x issues, please use https://github.com/ionic-team/ionic-v1)
[] 2.x
[X ] 3.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:

When using [VirtualScroll] and virtualtrackby on an ion-list with many ion-items with checkboxes, if some checkboxes are checked and then you scroll to the bottom of the list(about 1000 items), and scroll back up, it seems as if all the items are still checked, but their state is actually unchecked, because an ionChange event does not set it back to checked.
Expected behavior:

It seems with virtual scroll it destorys and unchecks the items, but remembers what items were checked. On the destroy it sends an ionChange event that the items are not not checked, or false. It should not send the ionChange event and "uncheck" the item. This causes issues when the list is longer than about 100 items, and any checked items from earlier in the list are essentially "gone".
Steps to reproduce:

insert any relevant code here
HTML Code:
<ion-content>
    
    <ion-list [virtualScroll]="companyCheckObject"  virtualTrackBy>
    <ion-item *virtualItem="let company">
    <ion-label> {{company.Company}}</ion-label>
        <ion-checkbox [(ngModel)]="company.isChecked" (ionChange)="checkBoxChecked(company.isChecked,company.Company,company.ID)" checked="company.isChecked">          
   </ion-checkbox>
   </ion-item>
   </ion-list>
     <ion-fab right bottom style="margin-right: 5vw;">
    <button ion-fab color="primary" (click)="openUpdateWarranty($event)"><ion-icon name="add"></ion-icon></button>
    </ion-fab>
</ion-content>

.ts code

checkBoxChecked(state,companyName,companyId)
{

    if(state == true)
    {
       this.companiesToSend.push({"id" : companyId, "name" : companyName, "isChecked" : true});
    }     
    if(state == false)
    {
        var index = this.companiesToSend.indexOf(companyId);
        this.companiesToSend.splice(index,1);
         // console.log(this.companiesToSend);
    }
    //console.log(this.companiesToSend);
}

**Other information:**
<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->
When using *ngFor instead, it behaves as expected, because the items are not destroyed on scrolling.
**Ionic info:** (run `ionic info` from a terminal/cmd prompt and paste output below):

insert the output from ionic info here

Cordova CLI: 6.5.0
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.7
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v7.6.0
Xcode version: Not installed

@JacobT14
Copy link
Author

Just as an FYI there is an easy workaround to just use (click) instead of (ionChange). That is probably the proper way and this technically isn't a bug if that is the case. I am kind of new to development so... :)

@ionitron-bot
Copy link

ionitron-bot bot commented Jun 21, 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 Jun 21, 2018
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jun 21, 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

1 participant