Angular 2 : Give value to button based on dropdown menu value - html

I am new to angular 2.
I have a button and a drop down which is appeared. When I click on any of the option then its value should be given to the button .
.common_select_box {
width: 100%;
}
.common_select_box button {
border: thin #cfdadd solid;
border-radius: 0 !important;
width: 100%;
text-align: left;
padding: 7.45px 12px;
border-radius: 1.5px !important;
}
.common_select_box button .caret {
display: inline-block;
width: 0;
height: 0;
margin-right: 2px;
vertical-align: middle;
border-top: 6px dashed;
border-right: 6px solid transparent;
border-left: 6px solid transparent;
position: absolute;
top: 14px;
right: 5px;
}
.common_select_box ul.dropdown-menu {
border: 1px solid #cfdadd;
border-radius: 2px;
box-shadow: none !important;
width: 100%;
padding: 0px;
}
.common_select_box ul.dropdown-menu li {
padding: 5px 15px;
font-size: 12px;
list-style-type:none;
}
.common_select_box ul.dropdown-menu li:hover {
background: #edf1f2 !important;
}
<div class="common_select_box">
<!--give open class to below div when clicking on button-->
<div class="input-group-btn dropdown {{dropdown1? 'open':''}}" (click)="dropdown1=!dropdown1">
<button type="button" class="btn btn-default font_size_12 no_box_shadow ticket_info_subline_text_color" dropdown-toggle="" aria-haspopup="true" aria-expanded="false" >Select <span class="caret" style="color: #bfbfbf;"></span></button>
<ul class="dropdown-menu">
<li >Option 1</li>
<li >Option 2</li>
<li >Option 3</li>
</ul>
</div><!-- /btn-group -->
</div>
When I click on option 1 . then its value should be given to button tag.
Any Help Would be great.
Thank You.

This will work,
<div class="common_select_box">
<div class="input-group-btn dropdown {{dropdown1? 'open':''}}"
(click)="dropdown1=!dropdown1">
<button type="button" class="btn btn-default font_size_12 no_box_shadow
ticket_info_subline_text_color" dropdown-toggle=""
aria-haspopup="true" aria-expanded="false">{{selectedNav}}<span
class="caret" style="color: #bfbfbf;"></span> </button>
<ul class="dropdown-menu">
<li (click)="setNav(item)" *ngFor="let item of navs">{{item}}</li>
</ul>
in .ts file
export class PropertyComponent {
selectedNav: any; navs = ['option 1', 'option 2', 'option 3']
ngOnInit() {
this.selectedNav = 'select value';
}
setNav(nav){
this.selectedNav = nav;
}
}

Related

Browser adds extra closing tags

I have this code:
.link {
cursor: pointer;
}
.dropdown-content {
margin-top: 10px;
margin-left: -10px;
position: absolute;
min-width: 100px;
min-height: 50px;
color: #5A3895;
float: left;
display: none;
background-color: #FDEBCF;
border: 3px solid #999999;
}
.inside-dropdown-content {
margin-top: 10px;
margin-left: -10px;
position: absolute;
min-width: 100px;
min-height: 50px;
color: #5A3895;
float: left;
display: none;
background-color: #FDEBCF;
border: 3px solid #999999;
}
.dropdown-button:hover>.dropdown-content {
display: block;
background-color: #FDEBCF;
}
.dropdown-button:hover {
background-color: #FDEBCF;
}
.inside-dropdown-button:hover>.inside-dropdown-content {
display: block;
background-color: #FDEBCF;
}
.inside-dropdown-button:hover {
background-color: #FDEBCF;
}
.name-label p {
font-size: 30px;
margin: auto;
text-align: center;
}
.name-label {
float: left;
padding-left: 10px;
}
.header {
border: 1.5px solid #999999;
background-color: #FDEBCF;
font-size: 20px;
font-family: Arial;
overflow: hidden;
}
button:not(.impressum-link):not(.inside-dropdown-button) {
font-size: 20px;
min-width: 100px;
min-height: 50px;
color: #5A3895;
float: left;
background-color: #FDEBCF;
border-style: solid;
border-color: #999999;
border-width: 1px 3px 1px 3px;
}
.impressum-link {
font-size: 20px;
min-width: 100px;
min-height: 50px;
color: #5A3895;
float: right;
background-color: #FDEBCF;
border-style: solid;
border-color: #999999;
border-width: 1px 3px 1px 3px;
}
<div class="header">
<div class="dropdown">
<button type="button" class="link">
<span>Home</span>
</button>
</div>
<div class="dropdown">
<button type="button" class="dropdown-button">
<span>Publications</span>
<div class="dropdown-content">
<button type="button" class="inside-dropdown-button">
<span>Recent Publications</span>
<div class="inside-dropdown-content">
<p>year</p>
A link to whatever
</div>
</button>Other Publications</div>
</button>
</div>
<div class="name-label">
<p>Website</p>
</div>
<button type="button" class="link impressum-link">
<span>Impressum</span>
</button>
</div>
I put in everything as I don't know what causes the problem.
I want to have the inside-dropdown-button inside of dropdown-content, but the browser (tested on Firefox and Chrome) seems to change
<div class="dropdown">
<button type="button" class="dropdown-button">
<span>Publications</span>
<div class="dropdown-content">
<button type="button" class="inside-dropdown-button">
<span>Recent Publications</span>
<div class="inside-dropdown-content">
<p>year</p>
A link to whatever
</div>
</button>Other Publications</div></button>
</div>
to:
<div class="dropdown">
<button type="button" class="dropdown-button">
<span>Publications</span>
<div class="dropdown-content">
</div></button><button type="button" class="inside-dropdown-button">
<span>Recent Publications</span>
<div class="inside-dropdown-content">
<p>year</p>
A link to whatever
</div>
</button>Other Publications</div>
Notice the extra </div></button> before <button type="button" in the 5th line. This extra </div> causes there to be to many </div>'s, messing up the header class, and putting impressum-link outside of the header. Why is this and how do I get around it?
If I change it in the Browser, it works, but when I copy the code out of the browser to the script and remove the extra tags, it puts them in again.
A button cannot contain another button so the browser assumes you have made an error and closes it for you.
Also note that button elements cannot contain links (and vice versa).
Permitted content
Phrasing content but there must be no Interactive content

Dropdown toggle should come up if dropdown data goes out of screen

I am using Angular 8,
If we have 20 dropdowns <ul> entries, then dropdown toggle <ul> is going out of the screen.
I need to scroll the whole screen to see all the list of dropdown
Screenshot 1: DropDown that has 15 entries, but here I can see only 7 entries,
If I want to see all 15 entries then I need to scroll whole screen (Screenshot 2)
Screenshot 2: I need to scroll whole scree to see all data,
All I need to scroll only the dropdown till i find the last item or as soon as it goes out of screen, i need that dropdown to up , something like this Screenshot 3
Screenshot 3: I need something like this
#import "~src/assets/styles/bootstrap-theme";
#import "~src/assets/styles/icons";
:host {
form {
position: relative;
&.ng-invalid {
.dropdown-display {
border: $text-border-width solid $common-color-error-red;
background-color: $common-color-error-background;
z-index: 100; // to make sure the dropdown toggle border is drawn over the barcode button border
}
}
}
div.background {
position: fixed;
z-index: 1031;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
}
div.dropdown.disabled {
.form-control {
background-color: $input-disabled-bg;
}
.input-group-append button, .input-group-append .input-group-text {
background-color: $input-disabled-bg;
}
}
div.dropdown .dropdown-display {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
ul.dropdown-menu {
max-height: 50vh;
overflow-y: scroll;
z-index: 1040;
-webkit-overflow-scrolling: touch;
}
ul.dropdown-menu > li > a {
&:hover {
color:$common-color-white;
}
&.highlight-selection {
background-color: $highlight-input-background;
color: $highlight-input-text-color;
}
}
ul.dropdown-menu > li > input {
padding: 3px 15px; // px values since this is dependent on bootstrap, which also uses px for this
background-color: white;
}
ul.tags {
width: 100%;
display: flex;
flex-wrap: wrap;
list-style: none;
padding: 0;
margin-top: 0.5rem;
margin-bottom: 0;
border: $text-border-width solid darken($light-input-background, 5%);
li {
flex: 0 0 auto;
background-color: $light-input-background;
padding: 0.3125rem;
margin: 0.3125rem;
}
}
.input-group-append {
button {
padding-top: 0.0625rem;
padding-bottom: 0;
color: $primary;
background-color: $secondary;
border-color: $secondary;
}
.input-group-text {
background-color: $secondary;
border-color: $secondary;
}
}
}
HTML
<div class="background " *ngIf="showDropdownMenu" (click)="toggleDropdown()"></div>
<div class="dropdown">
<div class="input-group">
<div class="form-control flex-grow-1 dropdown-display"
(click)="toggleDropdownFromMenu($event)">
{{ model.selectedEntry}}
</div>
<div class="input-group-append" *ngIf="model.options.scannable">
<button class="btn btn-secondary"
type="button"
(click)="doScan($event)">
<fa-icon [icon]="faBarcode" size="2x"></fa-icon>
</button>
</div>
<div class="input-group-append"
(click)="toggleDropdownFromMenu($event)">
<fa-icon [icon]="faCaretDown" class="input-group-text"></fa-icon>
</div>
<span class="sr-only">Toggle Dropdown</span>
</div>
<ul class="dropdown-menu " role="menu" [ngClass]="{ show: showDropdownMenu }">
<li role="menuitem">
<input type="text"
formControlName="searchInput"
*ngIf="model.value.length > 3"
(click)="$event.stopPropagation()"
class="form-control"
[placeholder]="strings.searchPlaceholder"
>
</li>
<li role="menuitem"
*ngFor="let entry of searchMatchingEntries">
<a class="dropdown-item"
(click)="onSelected(entry)"
[ngClass]="{'highlight-selection':isSelected(entry)}">{{entry.displayName}}</a>
</li>
</ul>
</div>

Dropdown Menu Automatically Open in IE

I'm making a landing page for a client with a dropdown menu. I'm using bootstrap. I've been having an issue where the dropdown options are already expanded on page load, but only for IE. They also do not have any of the normal formattings for an 'expanded' dropdown (background color should be white, it's not, etc.) Instead, all the li are translucent gray. The options are hoverable and selectable, but the dropdown menu will not close (the caret is essentially unresponsive).
This problem has happened before, on other sites, for this same client. The weirdest thing is, in the past, I have been able to get it to work by merely uploading the folder again to the client's servers. Same code, not working once, then uploaded again and then working. For the life of me, I can't figure out why this is happening
.hero .hero-selection select {
width: 250px;
border: none;
font-size: 14px;
font-family: Proxima Nova Thin;
-moz-box-shadow: 0 0 0 35px rgba(255, 255, 255, .2);
-webkit-box-shadow: 0 0 0 35px rgba(255, 255, 255, .2);
box-shadow: 0 0 0 35px rgba(255, 255, 255, .2);
background-color: #FFF;
color: #999;
border-radius: 0!important;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
appearance: none;
padding: 15px 10px 10px;
}
.hero .hero-form-container .dropdown-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
font-size: 14px;
text-align: left;
list-style: none;
background-color: #fff;
background-clip: padding-box;
border: 1px solid rgba(0, 0, 0, .15);
border-radius: 4px;
box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
margin: 2px 0 0;
padding: 5px 0;
}
.hero .hero-form-container .dropdown-menu>li>a {
display: block;
clear: both;
font-weight: 400;
line-height: 1.42857143;
color: #333;
white-space: nowrap;
padding: 3px 20px;
}
.hero .hero-form-container ul {
width: 250px;
top: 91px;
border-radius: 0;
border: none;
background-color: #FFF;
color: #999;
padding: 0;
}
.hero .hero-form-container ul li a:hover {
background-color: #99d425;
font-family: Proxima Nova Thin;
font-size: 14px;
color: #999;
padding: 5px 5px 5px 15px;
}
.hero .hero-form-container ul li a {
font-family: 'Proxima Nova Thin';
font-size: 14px;
color: #999;
text-decoration: none;
padding: 5px 5px 5px 15px;
}
<div class="row">
<div class="col-sm-6 pull-left"><img id="nats-logo" style="" src="img/nats-logo-red.png" alt=""></div>
<div class="col-sm-6">
<div class="hero">
<div class="hero-form">
<div class="dropdown hero-selection">
<h5>Select your utility below:</h5>
<h2 style="margin-top: 20px">My Electricity Utility is:</h2>
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-expanded="true"> Select One<span class="caret"></span> </button>
<ul class="dropdown-menu" role="menu">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" value="notlisted" class="is-active">[not listed]</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" value="EBG">BGE</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" value="CNM">Delmarva Power (MD)</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" value="PED">Pepco (DC)</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" value="PEM">Pepco (MD)</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" value="APM">Potomac Edison</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" value="SME">SMECO</a></li>
</ul>
</div>
<form action="https://one.wglenergy.com/portal/rc_engine_by_ldc.php" id="form1">
<input type="hidden" name="super_rc" value="NATS">
<input type="hidden" name="cust_type" value="RES">
<input type="hidden" name="ldc_g" id="ldc_g">
<input type="hidden" name="ldc_e" id="ldc_e">
<input type="submit" id="go-button" value="See Your Pricing">
</form>
</div>
</div>
</div>
</div>
</div>

Fixed list item in dropdown menu UL

Its possible to have an LI fixed at a position and make the rest of the LI scrollable?
I want to have a ul where the first item is fixed, since its a search box, and make the other items, that are loaded with ng-repeat, scrollable.
I came to a solution but it's not UX ok...
My html:
<ul ng-if="filter.isSearchListType && hasFilterValues(filter)" class="dropdown-menu">
<li class="individual-search">
<input type="search" ng-model="searchInputText" class="form-group filter-input" placeholder="Nombre o E-mail" />
<i ng-show="searchInputText" class="fa fa-remove clear-search-icon" aria-hidden="true" ng-click="searchInputText = ''; $event.stopPropagation()"></i>
<i class="fa fa-search search-icon" aria-hidden="true" ng-click="$event.stopPropagation()"></i>
</li>
<li>
<ul class="pre-scrollable2">
<li ng-repeat="filterValue in filter.values | searchInData:searchInputText">
<a href="#" ng-click="selectFilterValue(filter, filterValue.id)" ng-class="{ 'selected': isSelectedFilter(filter, filterValue.id) }">
{{filterValue.label}}
</a>
</li>
</ul>
</li>
</ul>
CSS pre-scrollable2 is kinda a copy of dropdown-menu:
.pre-scrollable2 {
max-height: 340px;
overflow-y: scroll;
/*list-style-type: none;*/
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
/*display: none;*/
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 14px;
text-align: left;
list-style: none;
background-color: #fff;
-webkit-background-clip: padding-box;
background-clip: padding-box;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, .15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
}
.pre-scrollable2 > li > a {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.42857143;
color: #333;
white-space: nowrap;
}
.pre-scrollable2 > li > a:hover,
.pre-scrollable2 > li > a:focus {
color: #262626;
text-decoration: none;
background-color: #f5f5f5;
}
In my experience you have to seperate the two lists and stack them on top of eachother to make them look like one list. then the top list set the position to fixed for the fixed search bar then the bottom set overflow to auto to get a scroll effect. create a navbar class set its width to whatever and the height to 100vh
<div class="navbar">
<ul ng-if="filter.isSearchListType && hasFilterValues(filter)" class="searchbar">
<li class="individual-search">
<input type="search" ng-model="searchInputText" class="form-group filter-input" placeholder="Nombre o E-mail" />
<i ng-show="searchInputText" class="fa fa-remove clear-search-icon" aria-hidden="true" ng-click="searchInputText = ''; $event.stopPropagation()"></i>
<i class="fa fa-search search-icon" aria-hidden="true" ng-click="$event.stopPropagation()"></i>
</li>
</ul>
<ul class="bottomlist">
<li ng-repeat="filterValue in filter.values | searchInData:searchInputText">
<a href="#" ng-click="selectFilterValue(filter, filterValue.id)" ng-class="{ 'selected': isSelectedFilter(filter, filterValue.id) }">
{{filterValue.label}}
</a>
</li>
</ul>
</div>
<style>
.navbar {
position: fixed;
left: 0;
top: 0;
bottom: 0;
height: 100vh;
width: 20vw;
}
.searchbar {
postion: fixed;
top: 0;
}
.bottomlist {
overflow: auto;
postion: relative;
}
</style>

Bootstrap Modal Dialog off screen with white background

I am working with this snippet: http://bootsnipp.com/snippets/featured/modal-login-with-jquery-effects
Using bootstrap 3.3.6
Two questions:
Why is there a white background behind my modal? Or how should I debug this?
Why is my modal only centering within that white background? I need it to center in the middle of the screen.
My css:
/* #####################################################################
#
# Project : Modal Login with jQuery Effects
# Author : Rodrigo Amarante (rodrigockamarante)
# Version : 1.0
# Created : 07/28/2015
# Last Change : 08/02/2015
#
##################################################################### */
/*#import url(http://fonts.googleapis.com/css?family=Roboto);
* {
font-family: 'Roboto', sans-serif;
}*/
#login-modal .modal-dialog {
width: 350px;
position: relative;
top: 50%;
left: 50%;
margin-top: -25px;
margin-left: 0px;
padding: 20px;
}
#login-modal input[type=text], input[type=password] {
margin-top: 10px;
}
#div-login-msg,
#div-lost-msg,
#div-register-msg {
border: 1px solid #dadfe1;
height: 30px;
line-height: 28px;
transition: all ease-in-out 500ms;
}
#div-login-msg.success,
#div-lost-msg.success,
#div-register-msg.success {
border: 1px solid #68c3a3;
background-color: #c8f7c5;
}
#div-login-msg.error,
#div-lost-msg.error,
#div-register-msg.error {
border: 1px solid #eb575b;
background-color: #ffcad1;
}
#icon-login-msg,
#icon-lost-msg,
#icon-register-msg {
width: 30px;
float: left;
line-height: 28px;
text-align: center;
background-color: #dadfe1;
margin-right: 5px;
transition: all ease-in-out 500ms;
}
#icon-login-msg.success,
#icon-lost-msg.success,
#icon-register-msg.success {
background-color: #68c3a3 !important;
}
#icon-login-msg.error,
#icon-lost-msg.error,
#icon-register-msg.error {
background-color: #eb575b !important;
}
#img_logo {
max-height: 100px;
max-width: 100px;
}
/* #########################################
# override the bootstrap configs #
######################################### */
.modal-backdrop.in {
filter: alpha(opacity=50);
opacity: .8;
}
.modal-content {
background-color: #ececec;
border: 1px solid #bdc3c7;
border-radius: 0px;
outline: 0;
margin: 15% auto;
position: relative;
}
.modal-header {
min-height: 16.43px;
padding: 15px 15px 15px 15px;
border-bottom: 0px;
}
.modal-body {
position: relative;
padding: 5px 15px 5px 15px;
}
.modal-footer {
padding: 15px 15px 15px 15px;
text-align: left;
border-top: 0px;
}
.checkbox {
margin-bottom: 0px;
}
.btn {
border-radius: 0px;
}
.btn:focus,
.btn:active:focus,
.btn.active:focus,
.btn.focus,
.btn:active.focus,
.btn.active.focus {
outline: none;
}
.btn-lg, .btn-group-lg>.btn {
border-radius: 0px;
}
.btn-link {
padding: 5px 10px 0px 0px;
color: #95a5a6;
}
.btn-link:hover, .btn-link:focus {
color: #2c3e50;
text-decoration: none;
}
.glyphicon {
top: 0px;
}
.form-control {
border-radius: 0px;
}
My html:
!-- BEGIN # MODAL LOGIN -->
<div class="modal fade" id="login-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" align="center">
<img class="img-circle" id="img_logo" src="images/hhb.png">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</div>
<!-- Begin # DIV Form -->
<div id="div-forms">
<!-- Begin # Login Form -->
<form id="login-form">
<div class="modal-body">
<div id="div-login-msg">
<div id="icon-login-msg" class="glyphicon glyphicon-chevron-right"></div>
<span id="text-login-msg">Type in User Name and Password</span>
</div>
<input id="login_username" class="form-control" type="text" placeholder="Username (type ERROR for error effect)" required>
<input id="login_password" class="form-control" type="password" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
<div class="modal-footer">
<div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Login</button>
</div>
<div>
<button id="login_lost_btn" type="button" class="btn btn-link">Lost Password?</button>
<button id="login_register_btn" type="button" class="btn btn-link">Register</button>
</div>
</div>
</form>
<!-- End # Login Form -->
Solved this. Here is what I did for any one just starting:
You can use the developer tools to identify where there might be a conflict in your code.
For me I was referencing two conflicting versions of bootstrap.