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

Select2 v4 not clearing when reloading data dynamically #3348

Closed
isAlmogK opened this issue May 12, 2015 · 3 comments
Closed

Select2 v4 not clearing when reloading data dynamically #3348

isAlmogK opened this issue May 12, 2015 · 3 comments

Comments

@isAlmogK
Copy link

I upgrade to the latest version 4, before the update everything was working fine. But now when I reload the data dynamically it's not clearing the old data in the UI even if the data is not in the array anymore.

I also tried $("#blocks").select2("val", null); which had no effect.

 $("#producers").select2({ data: producersList, placeholder: 'please select producer'}).on('change', function (e) {
        var producerId = $("#producers").select2('val');

        console.log(blocksList); 
        blocksList.length = 0;
        console.log(blocksList); // array is empty 

        $("#blocks").select2("val", null);
        blocksList = Blocks.find({producerId: producerId}).map(function (obj) {
            var blockProductionId =  obj.productionUnitCode + obj.subCode.toString();
            return {text: blockProductionId, id: obj._id, fieldStatus:obj.fieldStatus};
        });

        console.log(blocksList); // correct data 

        // Updates the block data and sets on change event
        $("#blocks").select2({ data: blocksList, placeholder: mf('pleaseSelectBlock', 'please select block')});
        $('#blocks').prop("disabled", false);
    });
@kevin-brown
Copy link
Member

Covered in #3185 (comment).

@kevin-brown
Copy link
Member

Actually, reopening this until it is documented.

@stale
Copy link

stale bot commented Mar 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status: stale label Mar 13, 2019
@stale stale bot closed this as completed Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants