Select2 bad positioning when dropdown doesn't fit in reamining container height - jquery-select2

I have this problem with the selec2 plugin where the drop down position it's not aligned with the select. (too bad I can't post pictures, no reputation points, I'll use my imagination:)
The way it looks:
|--------Dropdown------|
|-------Select--------|
The way it should look:
|--------Dropdown-----|
|-------Select--------|
(The dropdown it's oppening up because the select its on the bottom edge of the page)
I have read about jquery having issues to calculate offsets of elements that had a css transformation, and tried every workaround and tried to comment every transform word in my code... no results.
I've found that the issue is fixed when I give my html body enough height to make it scroll (I don't want that). Do you guys have some ideas? (see my code bellow):
HTML:
<div style="margin-left:50px;width:250px; float: left;">
<select name="marca" id="marca" data-placeholder="Marca"
class="select2" tabindex="15">
<option value=""></option>
<option class="response" value="ALCATEL" text="Alcatel">Alcatel</option>
<option class="response" value="APPLE" text="Apple">Apple</option>
<option class="response" value="AVVIO" text="Avvio Full">Avvio
Full</option>
<option class="response" value="ENSPIRE" text="Cellon Enspire">Cellon
Enspire</option>
<option class="response" value="ERIC" text="Ericsson">Ericsson</option>
<option class="response" value="HTC" text="High Tech Computer ">High
Tech Computer</option>
<option class="response" value="HUAWEI" text="Huawei">Huawei</option>
<option class="response" value="IMAC" text="Imac">Imac</option>
<option class="response" value="LG" text="Lg">Lg</option>
<option class="response" value="M4TEL" text="M4tel">M4tel</option>
<option class="response" value="MOTO" text="Motorola">Motorola</option>
<option class="response" value="NOKI" text="Nokia">Nokia</option>
<option class="response" value="PALM" text="Palmone Modelo">Palmone
Modelo</option>
<option class="response" value="PACO" text="Pantech Co., Ltd">Pantech
Co., Ltd</option>
<option class="response" value="PCD"
text="Personal Communication Device">Personal
Communication Device</option>
<option class="response" value="SAGEM" text="Sagem">Sagem</option>
<option class="response" value="SAMS" text="Samsung">Samsung</option>
<option class="response" value="SWT"
text="Servicell Wireless Technologie">Servicell Wireless
Technologie</option>
<option class="response" value="SIWI" text="Sierra Wireless">Sierra
Wireless</option>
<option class="response" value="SKTE" text="Sk Teletec Co.,ltd">Sk
Teletec Co.,ltd</option>
<option class="response" value="TELU" text="Telular">Telular</option>
<option class="response" value="VERYKOOL" text="Verykool">Verykool</option>
<option class="response" value="VKMOB" text="Vk Mobile">Vk
Mobile</option>
<option class="response" value="ZONDA" text="Zonda">Zonda</option>
<option class="response" value="ZTE" text="Zte Corporation">Zte
Corporation</option>
</select>
</div>
The select CSS:
#disponibilidadForm select {
width: 245px;
}
#modelo,#marca {
overflow: hidden;
}
.select2-offscreen,.select2-offscreen:focus {
clip: rect(0, 0, 0, 0);
width: 1px;
height: 1px;
border: 0;
margin: 0;
padding: 0;
overflow: hidden;
position: absolute;
outline: 0;
left: 0px;
}
user agent stylesheetkeygen,select,select[size="0"],select[size="1"] {
border-radius: 0px;
}
user agent stylesheetselect {
-webkit-appearance: menulist;
box-sizing: border-box;
-webkit-align-items: center;
border: 1px solid;
border-image-source: initial;
border-image-slice: initial;
border-image-width: initial;
border-image-outset: initial;
border-image-repeat: initial;
white-space: pre;
-webkit-rtl-ordering: logical;
color: black;
background-color: white;
cursor: default;
}
user agent stylesheetkeygen,select {
border-radius: 5px;
}
user agent stylesheetinput,textarea,keygen,select,button,isindex {
margin: 0em;
font: -webkit-small-control;
color: initial;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
}
user agent stylesheetinput,textarea,keygen,select,button,isindex,meter,progress
{
-webkit-writing-mode: horizontal-tb;
}
Inherited from div.float_left
.float_left {
text-align: left;
}
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
font-size: 100%;
font: inherit;
}
Inherited from form#disponibilidadForm
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
font-size: 100%;
font: inherit;
}
Inherited from div.formulario.float_right
.float_right {
text-align: left;
}
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
font-size: 100%;
font: inherit;
}
Inherited from div
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
font-size: 100%;
font: inherit;
}
Inherited from div.contenido
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
font-size: 100%;
font: inherit;
}
Inherited from body
body {
line-height: 1;
}
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
font-size: 100%;
font: inherit;
}
Inherited from html
html {
font-family: Arial, Helvetica, sans-serif;
}
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
font-size: 100%;
font: inherit;
}

Adding the css property "overflow: scroll;" to the html body fixed the position of the dropdown, and the page doesn't get scrolled

Related

css input number field rendering weird on certain versions of ios

The input number field doesn't render properly on ios. The number gets cut off at the bottom. It works for certain ios versions but not other ones. I'm stuck, please help
input[type=submit] {
text-align: center;
}
.page_q3 input[type="number"] {
height: 91px;
width: 110px;
color: #464356;
font-family: "Source Sans Pro";
font-size: 82px;
font-weight: 600;
text-align: center;
border: none;
border-bottom: 2px solid #464356;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
<div class="page_q3">
<div class="div_minus"><img src="<?=$templateDir?>/images/minus.jpg" class="minus" data-quantity="minus" data-field="<?=$inputName?>" /> </div>
<div class="div_number"><input type="number" id="<?=$inputName ?>" name="<?=$inputName?>" value="<?=$_SESSION[$inputName]?>" placeholder="0" /> </div>
<div class="div_plus"><img src="<?=$templateDir?>/images/plus.jpg"
class="plus" data-quantity="plus" data-field="<?=$inputName?>" /> </div>
</div>
What it should look like
https://ibb.co/y8msSpL
what it actually looks like
https://ibb.co/rkbyPF5
You might want to try removing the border-radius and padding that are added by iOS by default:
.page_q3 input[type="number"] {
-webkit-border-radius: 0;
border-radius: 0;
padding: 0;
}

Changing colors and styling of collection_select dropdown with rails bootstrap and select2 implemented

I want to change the colors and style a dropdown in rails to match the rest of my web app styling. I am using Rails, Bootstrap, and select2 and I have no idea where to add css and how to even begin accessing the the different parts of the dropdown so that I can color them and make them fit with the rest of the design on the app.
this is the implementation of the dropdown
<%= collection_select(:id, :name, #product, :id, :name,{:include_blank => true},{class: "js-example-basic-single" }) %>
Please advise me on how to accomplish styling this item, thanks.
I'm not sure what your question is so I will try to answer it as best as I can. I believe you should be adding your CSS to the application.css file that should be under app\assets\stylesheets. Then if you want to customize all your dropdowns the same you can use the select tag in css. Here is an example
select {
position: relative;
display: inline-block;
cursor: pointer;
text-align: center;
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
border-radius: 3px;
border: none;
background: #f1f1f1;
padding: 2px;
}
select:hover {
background-color: dodgerblue;
}
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Quick update
adding the below worked for me... suprising this isnt in the bootstrap gem
select {
display: block;
width: 100%;
height: calc(1.5em + 0.75rem + 2px);
padding: 0.375rem 0.75rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: 0.25rem;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

Unable to display right tick mark in checkbox in tablets and iPad

I have following code, it displays check mark ticked on desktop. But doesn't work on iPad and tablets. Functionality is working but right mark is not shown.
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 borderAtRight"
<!-- Dropdown and Menu -->
<div class="btn-group topFilterCtrl filterDropdn" dropdown
dropdown-append-to-body
id="ddlStatus">
<div id="btn-append-to-body" type="button"
class="btn btn-primary panelTextFont14 noBorder"
dropdown-toggle>
Status<span class="caret caretSpan"></span>
</div>
<ul class="dropdown-menu dropDownLabel" role="menu"
aria-labelledby="btn-append-to-body"
ng-show="!vm.showthis">
<div class="customScroll">
<li role="menuitem" class="changeColorOnHover"
ng-repeat="optionThis in vm.List track by $index"
ng-show="list.value != null">
<a href="#">
<div class="checkbox" id="{}index}"
ng-show="this.value != null"
ng-click="vm.applyFilterForResultCount()"
ng-change="vm.getCount(this)"
ng-model="this.flag">
<label>
<input type="checkbox"
ng-click="vm.clickStatusCheckBox(this);$event.stopPropagation();"
ng-show="this.value != null"/>
{{this.value}}
</label>
</div>
</a>
</li>
</div>
<!--Clear div-->
<li role="menuitem" class="btn btn-default buttonli"
ng-click="vm.clearAll()">
<a href="#">
<p>
<span class="clearAllBtn">Clear</span>
<span class="dropDownBtnItem"> – All </span>
</p>
</a>
</li>
</ul>
</div>
</div>
.topFilterCtrl{
text-align: left;
vertical-align: middle;
padding-top: 8%;
padding-bottom: 0%;
border-radius: 0;
margin-top: 0%;
box-shadow: none;
outline: none;
border:none;
width:100%;
}
portrait:
div.borderAtRight .filterDropdn{
padding-top:14%;
}
.filterDropdn{
padding-top: 10%;
height: 50px;
max-height: 50px;
overflow: hidden;
}
.noBorder{
text-align: left;
width:#full-width;
box-shadow: none;
outline: none;
min-width: 80%;
padding: 0;
height: auto;
min-height: 36px;
border-top-color: none;
border-top-style: none;
border-top-width: none;
border-right-color: none;
border-right-style: none;
border-right-width: none;
border-bottom-color: none;
border-bottom-style: none;
border-bottom-width: none;
border-left-color: none;
border-left-style: none;
border-left-width: none;
}
.dropDownLabel{
margin:0 0 0 -16px;
}
.customScroll{
height: auto;
overflow-x: hidden;
max-height:360px;
}
.customScroll>li>a,
.customScroll>li>a:hover,
.customScroll>li>a:active,
.customScroll>li>a:focus {
display: block;
padding: 1px 22px;
clear: both;
white-space: nowrap;
text-decoration : none;
}
.buttonli {
border-left: 0;
border-right: 0;
border-radius: 0;
margin: 2px 0px 2px 0px;
width: 100%;
background-color:#E4EAEF;
}
li.buttonli > a > p{
margin-bottom:0;
}
input[type="checkbox"]{
-webkit-appearance: checkbox;
}
I found this: https://github.com/angular-ui/bootstrap/issues/2017
But not sure how do I implement it, where should I really include this directive in my code as I am very new to AJS?
The checkbox may not display correct because the input element is nested inside the label element (even though it may be allowed, it confuses the purposes of the input and the label).
If the issue is about the checkbox not being checked by default, you might need to check out the ng-checked="expression" syntax for Angular.

jQuery Mobile forms combining input elements

When using jQuery mobile, is it possible to combine a checkbox or button with a text input? Something like in my image below.
I want to use it as field validation so it will turn red or green when user updates the field.
jQuery Mobile does not include this, but you can do it via CSS.
Here is a DEMO with a couple of options
The first uses a table, so the left button is always the same size and the input grows/shrinks on window resize. While the second option uses a div and bothe button and label grow shrink.
Fot the table, the css removes borders and spacing on the table and sets the first td width to a constant value. The rest of the css makes the button and input look right:
<table id="specialContTbl">
<tr>
<td class="btntd">
<button data-role="none" id="btn">B</button>
</td>
<td class="inptd">
<input data-role="none" type="text" id="inp1" name="inp1" value="" placeholder="enter some text" />
</td>
</tr>
</table>
#specialContTbl {
border-spacing: 0;
border-collapse: collapsed;
}
#specialContTbl td {
padding:0;
margin: 0;
border: 0;
vertical-align: top;
}
#specialContTbl td:first-child{
width: 60px;
}
#specialContTbl{
width: 100%;
}
#specialContTbl button, #specialContTbl input {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#specialContTbl button {
font-weight: normal;
background: #00f050;
padding: 5px;
color: #333;
border: 1px solid #d4d4d4;
border-right: 0;
border-bottom-left-radius:1em;
border-top-left-radius: 1em;
line-height: 28px;
height: 38px;
width: 100%;
float: left;
text-align: center;
cursor: pointer;
white-space:nowrap;
}
#specialContTbl input {
width: 100%;
height: 38px;
padding: 8px;
border: 1px solid #d4d4d4;
border-bottom-right-radius: 1em;
border-top-right-radius: 1em;
line-height: 18px;
float: right;
box-shadow: inset 0px 2px 2px #ececec;
}
#specialContTbl input:focus {
outline: 0;
}

Unexpected result with jQuery.after

I have an application with nearly 70 items in a <select> that allow multiple selection.
I'm trying to replace its behavior by two lists, where the user can drag/drop between a source list to a target list. The initial select should reflect the moves.
I'm trying to make it generic because I have to reuse the behavior in several pages, sometimes several times in the same page.
What I have by now (I reduced the actual number of items for readability) :
<div style="border: solid 1px red; overflow:auto">
<select name="lst1" multiple="multiple" id="lst1" class="go">
<option value="1">Element N°1</option>
<option value="2">Element N°2</option>
<option selected="selected" value="3">Element N°3</option>
<option value="4">Element N°4</option>
<option value="5">Element N°5</option>
</select>
</div>
<script type="text/javascript">
$(function () {
$(".go").each(function (index, el) {
var source = document.createElement("ul");
var target = document.createElement("ul");
$(el).after(source);
$(el).after(target);
$(source).addClass("sourceItems");
$(target).addClass("targetItems");
$(el + "option:selected").each(function (index2, sub) {
var item = document.createElement("li");
item.textContent = $(sub).text();
$(target).append(item);
});
$(el + "option:not(:selected)").each(function (index2, sub) {
var item = document.createElement("li");
item.textContent = $(sub).text();
$(source).append(item);
});
$(source).sortable({ connectWith : target});
$(target).sortable({ connectWith : source });
});
});
</script>
<style type="text/css">
.sourceItems, .targetItems { list-style-type: none; float:left; margin: 0; padding: 0; margin-right: 10px; background: #eee; padding: 5px; width: 200px; border: solid 1px black; }
.sourceItems li, .targetItems li { margin: 5px; padding: 5px; width: 180px; height: 12px; cursor: move; }
</style>
This code is producing unexpected result :
The "target" list's generated DOM looks like ok :
<ul class="targetItems ui-sortable">
<li>Element N°3</li>
<li>Element N°7</li>
<li>Element N°8</li>
<li>Element N°14</li>
<li>Element N°20</li>
<li>Element N°15</li>
<li>Element N°21</li>
</ul>
but the "source" list's generated DOM is a mess (it contains the page DOM in each element)):
<li>
.sourceItems, .targetItems { list-style-type: none; float:left; margin: 0; padding: 0; margin-right: 10px; background: #eee; padding: 5px; width: 200px; border: solid 1px black; }
.sourceItems li, .targetItems li { margin: 5px; padding: 5px; width: 180px; height: 12px; cursor: move; }
</li><li>
</li><li></li><li>
.sourceItems, .targetItems { list-style-type: none; float:left; margin: 0; padding: 0; margin-right: 10px; background: #eee; padding: 5px; width: 200px; border: solid 1px black; }
.sourceItems li, .targetItems li { margin: 5px; padding: 5px; width: 180px; height: 12px; cursor: move; }
Element N°1
Element N°2
Element N°3
Element N°4
Element N°5
Element N°6
Element N°7
Element N°8
Element N°9
...
Element N°3Element N°7Element N°8Element N°14Element N°15Element N°20Element N°21Element N°23Element N°27Element N°29Element.
I can't see what's wrong. I'd appreciate someone points me the root of the issue.
Here is a jsfiddle that show the issue : http://jsfiddle.net/gsYHb/
[edit] If i reverse the order of creating the source and target elements, the problem occurs on the other list :
var source = document.createElement("ul");
var target = document.createElement("ul");
$(el).after(target);
$(el).after(source);
in this case, this is the target list that is messy.
As you will see in http://jsfiddle.net/stevebeauge/gsYHb/6/, I have been able to solve my issue.
It was due to the $(this + "option:not(:selected)") selector that was returning the whole page.
Replacing this code with $(this).children("option:not(:selected)") make the script works (+ some other minor fixes)

Resources