admin管理员组文章数量:1414621
I've created a simple directive that consists in a form with few md-input and one md-select
.
I've used my directives in a few pages now and everything works fine, but now i would like to use it inside an md-dialog
and it's not working as expected, i can't close the md-select-menu if i click outside of it, even if i focus an md-input.
So the only two ways for the user to close the menu is to either select an option or dismiss the dialog.
It's not that bad but i found this rather annoying.
Here is the content of the dialog :
<md-dialog aria-label="Modal" ng-cloak flex="75">
<md-toolbar ng-class="md-primary">
<div class="md-toolbar-tools">
<h2 translate>personModal.update</h2>
<span flex></span>
<md-button class="md-icon-button" ng-click="cancel()">
<md-icon md-svg-src="img/ic_close_white.svg" aria-label="Close dialog"></md-icon>
</md-button>
</div>
</md-toolbar>
<person-form person="person"></person-form>
</md-dialog>
And the directive content :
<form name="createPersonForm" layout="row" layout-align="space-between center" class="bg-sec query-fields">
<md-input-container flex class="full-width-input">
<label translate>createPerson.form.firstname</label>
<input name="firstname" ng-model="person.firstname" required md-asterisk/>
<div ng-messages="createPersonForm.firstname.$error"
ng-show="createPersonForm.firstname.$touched">
<div ng-message="required" translate>
createPersonForm.errors.firstnameMissing
</div>
</div>
</md-input-container>
<!-- -->
<!-- Other md-inputs here -->
<!-- -->
<md-input-container flex class="consumption-filter full-width-input">
<label translate>createPerson.form.contact</label>
<md-select name="contact" ng-model="person.contactId" required>
<md-option ng-repeat="contact in contacts" ng-value="{{contact.id}}">
<span>{{contact.name}}</span>
</md-option>
</md-select>
<div class="md-errors-spacer"></div>
<div ng-messages="createPersonForm.contact.$error"
ng-show="createPersonForm.contact.$touched">
<div ng-message="required" translate>
createPersonForm.errors.contactMissing
</div>
</div>
</md-input-container>
<md-button class="md-raised bg-white" ng-click="createPerson()" ng-disabled="createPersonForm.$invalid" ng-hide="loading" ><span translate>createPersonForm.errors.createButton</span></md-button>
<md-progress-circular md-mode="indeterminate" class="md-accent" ng-show="loading"></md-progress-circular>
</form>
I'm using Angular 1.5 and Angular Material 1.0 .
I tried toying around with z-index, and upgrading angular/angular material, but it doesn't solve the problem.
I'm considering closing the menu programatically when the md-select looses focus, but i found that kinda ugly. And i don't know how do to do that yet.
Thanks in advance !
I've created a simple directive that consists in a form with few md-input and one md-select
.
I've used my directives in a few pages now and everything works fine, but now i would like to use it inside an md-dialog
and it's not working as expected, i can't close the md-select-menu if i click outside of it, even if i focus an md-input.
So the only two ways for the user to close the menu is to either select an option or dismiss the dialog.
It's not that bad but i found this rather annoying.
Here is the content of the dialog :
<md-dialog aria-label="Modal" ng-cloak flex="75">
<md-toolbar ng-class="md-primary">
<div class="md-toolbar-tools">
<h2 translate>personModal.update</h2>
<span flex></span>
<md-button class="md-icon-button" ng-click="cancel()">
<md-icon md-svg-src="img/ic_close_white.svg" aria-label="Close dialog"></md-icon>
</md-button>
</div>
</md-toolbar>
<person-form person="person"></person-form>
</md-dialog>
And the directive content :
<form name="createPersonForm" layout="row" layout-align="space-between center" class="bg-sec query-fields">
<md-input-container flex class="full-width-input">
<label translate>createPerson.form.firstname</label>
<input name="firstname" ng-model="person.firstname" required md-asterisk/>
<div ng-messages="createPersonForm.firstname.$error"
ng-show="createPersonForm.firstname.$touched">
<div ng-message="required" translate>
createPersonForm.errors.firstnameMissing
</div>
</div>
</md-input-container>
<!-- -->
<!-- Other md-inputs here -->
<!-- -->
<md-input-container flex class="consumption-filter full-width-input">
<label translate>createPerson.form.contact</label>
<md-select name="contact" ng-model="person.contactId" required>
<md-option ng-repeat="contact in contacts" ng-value="{{contact.id}}">
<span>{{contact.name}}</span>
</md-option>
</md-select>
<div class="md-errors-spacer"></div>
<div ng-messages="createPersonForm.contact.$error"
ng-show="createPersonForm.contact.$touched">
<div ng-message="required" translate>
createPersonForm.errors.contactMissing
</div>
</div>
</md-input-container>
<md-button class="md-raised bg-white" ng-click="createPerson()" ng-disabled="createPersonForm.$invalid" ng-hide="loading" ><span translate>createPersonForm.errors.createButton</span></md-button>
<md-progress-circular md-mode="indeterminate" class="md-accent" ng-show="loading"></md-progress-circular>
</form>
I'm using Angular 1.5 and Angular Material 1.0 .
I tried toying around with z-index, and upgrading angular/angular material, but it doesn't solve the problem.
I'm considering closing the menu programatically when the md-select looses focus, but i found that kinda ugly. And i don't know how do to do that yet.
Thanks in advance !
Share Improve this question asked Mar 20, 2017 at 16:19 FreegoFreego 4667 silver badges18 bronze badges 3- Did you figure out a fix? I am having the same problem. – Holt Commented Jul 25, 2017 at 18:12
- Had to do a dirty fix manipulating z-index and onClickListener of the md-scroll-mask when opening and closing the md-select – Freego Commented Jul 26, 2017 at 13:14
- @Holt in case you're interested i posted an answer with what i did – Freego Commented Jul 28, 2017 at 8:10
2 Answers
Reset to default 6Using the method proposed by Freego above throws an error for me on angular-material 1.1.5
TypeError: Cannot read property '$viewValue' of undefined
I got this fixed in angular-material 1.1.5 by setting the z-index for <md-backdrop />
alongside .md-select-menu-container
.
.md-select-menu-container {
z-index: 900;
}
md-backdrop.md-select-backdrop {
z-index: 899;
}
For those interested here is what i've done to fix my problem. I know it's not the most elegant solution, but it worked for me. If anyone has a better idea feel free to share with us !
HTML :
<md-input-container flex>
<label>Category</label>
<md-select ng-model="selectedCategory" md-on-open="dirtyFix()">
<md-option ng-repeat="cat in categories" ng-value="{{cat}}" ng-selected="$first">{{cat.name}}
</md-option>
</md-select>
</md-input-container>
JS :
$scope.dirtyFix= function () {
$timeout(function () {
$(".md-scroll-mask").css("z-index", 899);
$(".md-scroll-mask").click(function () {
$(".md-select-menu-container").remove();
$(".md-scroll-mask").css("z-index", -1);
});
}, 500);
}
CSS :
.md-select-menu-container {
z-index: 900;
}
Had to set a timeout to let the modal render and then toy with z-index and clicklistener.
It's far from perfect but maybe it'll inspire you !
本文标签: javascriptAngularMaterialmdselect in mddialog not closingStack Overflow
版权声明:本文标题:javascript - Angular-Material : md-select in md-dialog not closing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745182912a2646549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论