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

Losing selection in multiple with custom query #35

Open
piernik opened this issue Oct 16, 2015 · 0 comments
Open

Losing selection in multiple with custom query #35

piernik opened this issue Oct 16, 2015 · 0 comments

Comments

@piernik
Copy link

piernik commented Oct 16, 2015

If using multiple with custom query it's llosing selection.
in getSelection You call custom query function to fetch options. But often those option are defferent because of ajax. and earlier selected options are gone.
That's why You have to store previous selection
Change:

function getSelection(callback) {
    if (isMultiple) {
        getOptions(function (options) {
            var selection = [];
            for (var i = 0; i < options.length; i++) {
                var option = options[i];
                var viewValue = controller.$viewValue || [];
                if (viewValue.indexOf(option.id) > -1) {
                    selection.push(option);
                }
            }
            callback(selection);
        });
    } else {
        getOptions(function () {
            callback(optionItems[controller.$viewValue] || {obj: {}});
        });
    }
}

To:

var previousSelection = [];

function getSelection(callback) {
    if (isMultiple) {
        getOptions(function (options) {
            var selection = [];
            options = options.concat(previousSelection || []);
            for (var i = 0; i < options.length; i++) {
                var option = options[i];
                var viewValue = controller.$viewValue || [];
                if (viewValue.indexOf(option.id) > -1) {
                    selection.push(option);
                }
            }
            previousSelection = angular.copy(selection);
            callback(selection);
        });
    } else {
        getOptions(function () {
            callback(optionItems[controller.$viewValue] || {obj: {}});
        });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant