Put input inside select - html

Is there a way to place an INPUT field inside select?
<select name="menu_files" class="form-control" >
<option value="new_menu"> <input type="text"></option>
</select>

<datalist> Element
The datalist element is intended to provide a better mechanism for this concept.
<input type="text" name="example" list="exampleList">
<datalist id="exampleList">
<option value="A">
<option value="B">
</datalist>
For more information, see
MDN HTML Reference - <datalist> Element

It is not possible to place an INPUT field inside select. You can create your own custom plugin using jquery.
Try the following code:
$(document).ready(function() {
$('.dropdown-menu input').click(function(e) {
e.stopPropagation();
});
$('.dropdown a').click(function() {
$('.dropdown').addClass("open");
});
$('.dropdown-menu li').click(function() {
$('.dropdown-toggle b').remove().appendTo($('.dropdown-toggle').text($(this).text()));
});
});
.nav {
margin-left: 0;
margin-bottom: 20px;
list-style: none;
}
ul,
ol {
padding: 0;
margin: 0 0 10px 25px;
}
.dropup,
.dropdown {
position: relative;
}
.open>.dropdown-menu {
display: block;
}
.nav>li>a {
display: block;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
list-style: none;
background-color: #ffffff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
}
.dropdown-menu .divider {
height: 1px;
margin: 9px 1px;
overflow: hidden;
background-color: #e5e5e5;
border-bottom: 1px solid #ffffff;
}
.dropdown-menu>li>a {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 20px;
color: #333333;
white-space: nowrap;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="nav" role="navigation">
<li class="dropdown"> --Select Country--<b class="caret"></b>
<ul class="dropdown-menu" role="menu" aria-labelledby="drop2">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">USA</a>
</li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">UK</a>
</li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Russia</a>
</li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Others <input type="text" id="other"/></a>
</li>
</ul>
</li>
</ul>

We can achive it putting the input tag "next to" and not "inside" the select tag but forcing them into a limited and fixed area like a table td.
function selection(){
var selected=document.getElementById("select1").value;
if(selected==0){
document.getElementById("input1").removeAttribute("hidden");
}else{
//elsewhere actions
}
}
td{
width: 170px;
max-width: 170px;
overflow: hidden;
white-space: nowrap;
}
input{
width: 164px;
}
<table>
<tr>
<td>
<input id="input1" hidden="hidden" placeholder="input data">
<select onchange="selection()" id="select1">
<option value="-1"></option>
<option value="0">-make your own choice-</option>
<option value="1">choice 1</option>
<option value="2">choice 2</option>
</select>
</td>
</tr>
</table>
jsfiddle

You can also code like this.
<label class="text-left text-uppercase mt-1 sidenav-text w-100" for="category" onclick="menuShow();" >Category</label>
<p id="demo"></p>
and in remaining js
<script>
var demo = document.getElementById('demo');
function menuShow(){
demo.innerHTML = `
<input type="radio" name="select" value="women"> Women<br>
<input type="radio" name="select" value="women"> Men<br>
<input type="radio" name="select" value="women"> Kid<br>
<input type="radio" name="select" value="women"> Boy<br>
`;
}
</script>

Related

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>

how to remove blue highlight on hover in select, option inputs html for chrome

Almost 2 hours I've been trying to find out how to remove the blue highlight on hover in select, option inputs in HTML with CSS for chrome. how do we do this? here is a photo for better understanding.
Photo that represents my problem
here is my code if anyone is interested in helping me particularly
index.html :
<div style="margin-left:43px;" class="solutin_finder">
<select id="genre" onChange="return selectOption();" class="price1">
<option value="all" class="val">price range</option>
<option value="35" class="val">0$-35$</option>
<option value="36" class="val">36$ and over</option>
</select>
</div>
Unfortunately there isn't yet an option for styling this or removing the default background-color in Chrome.
The best option currently is to create your own select box from a UL
Something like this might work:
<style type="text/css">
.select ul li.option {
background-color: #DEDEDE;
box-shadow: 0px 1px 0 #DEDEDE, 0px -1px 0 #DEDEDE;
-webkit-box-shadow: 0px 1px 0 #DEDEDE, 0px -1px 0 #DEDEDE;
-moz-box-shadow: 0px 1px 0 #DEDEDE, 0px -1px 0 #DEDEDE;
}
.select ul li.option:hover {
background-color: #B8B8B8;
}
.select ul li.option {
z-index: 1;
padding: 5px;
list-style: none;
}
.select ul.closed li.option {
display: none;
}
.select ul.closed li:first-child {
display: block;
}
.select ul li {
cursor: default;
}
</style>
<div class="select">
<ul style="width:150px;" id="selectbox" class="closed">
<li values="1" class="option">Dropdown one</li>
<li values="2" class="option">Dropdown two</li>
<li values="3" class="option">Dropdown three</li>
</ul>
</div>
<script>
var s = document.getElementById("selectbox");
selectbox.onclick = function () {
selectbox.classList.toggle('closed');
}
</script>
Solution works only in IE (checked 10 and 11)
`
<select class="form-control">
<option>Option option option</option>
<option>Option option option</option>
<option>Option option option</option>
</select>
.form-control option:hover {
background: pink;
}
::selection, select:focus::-ms-value {
background-color: deeppink;
color: #000;
}
option:checked {
background-color: deeppink;
color: #000;
}
option:checked:hover, select:focus option:checked:hover {
background-color: deeppink;
color: #000;
}
`
https://jsbin.com/mejivij/2/edit?html,css,js,output
Custom Select Box
var selectComboBox = document.getElementById("select_combo_box");
var selectedValue = "";
selectComboBox.onclick = function() {
var targetOption = event.target;
if (targetOption.tagName != "LI") {
selectComboBox.classList.toggle('closed');
} else if (targetOption.getAttribute("value") == "0") {
selectComboBox.classList.toggle('closed');
} else {
var select = targetOption.parentNode;
var allOptions = select.children;
var firstOption = allOptions[0];
for (i in allOptions) {
if (isNaN(i)) {
break;
}
var option = allOptions[i];
if (option) {
if (option.classList.contains('selected')) {
option.classList.remove('selected');
}
}
}
selectedValue = targetOption.getAttribute("value");
// targetOption.classList.add('selected');
firstOption.children[0].innerHTML = targetOption.getInnerHTML();
selectComboBox.classList.toggle('closed');
}
};
function handleBodyClick() {
var tagName = event.target.tagName;
var parentTagName = event.target.parentNode.tagName;
if (!!tagName) {
if (tagName === 'LI' || tagName === 'UL' || parentTagName === 'LI') {
return;
}
}
if (!selectComboBox.classList.contains('closed')) {
selectComboBox.classList.add('closed');
}
}
window.addEventListener("wheel", function() {
handleBodyClick();
});
window.addEventListener("keyup", function() {
handleBodyClick();
});
window.addEventListener("keydown", function() {
handleBodyClick();
});
window.addEventListener("click", function() {
handleBodyClick();
});
.login-select ul li:first-child {
background-color: #747474 !important;
color: #D1D1D1;
font-size: 13px;
box-shadow: 0px 1px 0 #747474, 0px -1px 0 #747474 !important;
-webkit-box-shadow: 0px 1px 0 #747474, 0px -1px 0 #747474 !important;
-moz-box-shadow: 0px 1px 0 #747474, 0px -1px 0 #747474 !important;
}
.login-select ul li.option {
background-color: #5D5D5D;
color: #D1D1D1;
font-size: 13px;
box-shadow: 0px 1px 0 #5D5D5D, 0px -1px 0 #5D5D5D;
-webkit-box-shadow: 0px 1px 0 #5D5D5D, 0px -1px 0 #5D5D5D;
-moz-box-shadow: 0px 1px 0 #5D5D5D, 0px -1px 0 #5D5D5D;
}
.login-select ul li.option:hover {
background-color: #747474;
}
.login-select ul li.option {
z-index: 1;
padding: 5px;
list-style: none;
}
.login-select ul.closed li.option {
display: none;
}
.login-select ul.closed li:first-child {
display: block;
}
.login-select ul li {
cursor: default;
}
.login-select ul li span {
width: 10px;
float: right;
border-left: solid 1px;
height: 14px;
top: -24px;
padding: 8px 5px;
border-color: #5D5D5D;
}
<div class="login-select" style="width: 300px;">
<ul style="width:100%; padding: 0px;" id="select_combo_box" class="closed">
<li value="0" class="option"><div>Other Login Options</div><span class="glyphicon glyphicon-chevron-down"></span></li>
<li value="1" class="option">Option 1</li>
<li value="2" class="option">Option 2</li>
<li value="3" class="option">Option 3</li>
<li value="4" class="option">Option 4</li>
</ul>
</div>
Select / Option elements are rendered by the OS, not HTML. You cannot change the style of these elements.
But you can create custom select boxes with CSS and JavaScript check the URL below
https://www.w3schools.com/howto/howto_custom_select.asp

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>

How to fix border jagged isuue of ::before pseudo element for radio buttons?

Here's the Example of jsfiddle
I have created the dummy radio buttons with my custom CSS,
As you can see in above example border is looking jagged.
I have added below custom css for box shadow
input[type='radio']:checked + label:before {
background: #3A3A3A;
box-shadow: inset 0px 0px 0px 4px #DEDEDE;
}
Here you can see the difference
without border-radius it seems like --
with border-radius it seems like --
You can see the difference in these two images,
Please see above fiddle example and give some suggestions.
Add margin to the li
ul.gfield_radio li{
padding-bottom: 5px;
}
.gfield_radio input[type='radio']+label:before {
content: '';
background: #DEDEDE;
border: 1px solid #359947;
display: inline-block;
vertical-align: middle;
width: 40px;
height: 40px;
padding: 2px;
margin-right: 10px;
text-align: center;
border-radius: 50%;
box-sizing: border-box;
}
.gfield_radio input[type='radio'] {
display: none;
}
.gfield_radio input[type='radio']:checked+label:before {
background: #3A3A3A;
box-shadow: inset 0px 0px 0px 4px #DEDEDE;
}
ul {
list-style: none;
margin-left: 0;
}
ul.gfield_radio li {
padding-bottom: 5px;
}
ul.gfield_checkbox li label {
display: inline-block;
line-height: 1.2;
}
<ul class="gfield_radio" id="input_1_3">
<li class="gchoice_1_3_0">
<input name="input_3" type="radio" value="First Choice" id="choice_1_3_0" tabindex="2">
<label for="choice_1_3_0" id="label_1_3_0">
First Choice
</label>
</li>
<li class="gchoice_1_3_1">
<input name="input_3" type="radio" value="Second Choice" id="choice_1_3_1" tabindex="3">
<label for="choice_1_3_1" id="label_1_3_1">
Second Choice
</label>
</li>
<li class="gchoice_1_3_2">
<input name="input_3" type="radio" value="Third Choice" id="choice_1_3_2" tabindex="4">
<label for="choice_1_3_2" id="label_1_3_2">
Third Choice
</label>
</li>
</ul>

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

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;
}
}