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

Multi-select disappears when adding ng-model attribut #139

Closed
SteveBunlon opened this issue Mar 31, 2016 · 4 comments
Closed

Multi-select disappears when adding ng-model attribut #139

SteveBunlon opened this issue Mar 31, 2016 · 4 comments

Comments

@SteveBunlon
Copy link

Hey there ! I'm facing a problem with material-select and multiple.

On a select input, I'm using ng-options, material-select, and multiple. The problem is that when I click on an item, the dropdown disappears as a normal select (without the multiple). The item is well checked but if I want to click on another one, I have to open again the dropdown. And I found that if I remove the ng-model attribut, it works fine, but I need it !

If someone could work on it or help me !

Great job on this framework BTW.

Steve.

@SteveBunlon
Copy link
Author

Hi again, I figured out my problem with a colleague, in the code of the librairie we can found this directive :

.directive("materialSelect", ["$compile", "$timeout", function ($compile, $timeout) {
            return {
                link: function (scope, element, attrs) {
                    if (element.is("select")) {
                        function initSelect() {
                            element.siblings(".caret").remove();
                            scope.$evalAsync(function() {
                              element.material_select();
                            });
                        }
                        $timeout(initSelect);
                        if (attrs.ngModel) {
                            scope.$watch(attrs.ngModel, initSelect);
                        }
                        if ("watch" in attrs) {
                            scope.$watch(function () {
                                return element[0].innerHTML;
                            }, function (oldVal, newVal) {
                                if (oldVal !== newVal) {
                                    $timeout(initSelect);
                                }
                            });
                        }
                    }
                }
            };
        }]);

By removing the lines below, the multiple select works perfectly :

 if (attrs.ngModel) {
     scope.$watch(attrs.ngModel, initSelect);
 }

I hope that will help.

Regards.

BUNLON Steve

@dhaval85
Copy link
Contributor

@SteveBunlon

Thanks man. I've created a pull request here. https://github.com/krescruz/angular-materialize/pull/143/commits

Regards,
Dhaval

@webbiesdk
Copy link
Collaborator

I'm closing this issue, since it has now been fixed in #143.

If you don't think it has been fixed, comment/reopen the issue.

@webbiesdk
Copy link
Collaborator

I need to read the issue before closing it.
The issue is that when selecting something inside a multiple-select, the dropdown closes.
This doesn't happen in materialize (the one without angular), so this is still an issue.

Reopened.

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

3 participants