Skip to content

Commit

Permalink
added custom selects and examples, TODO:adjust iframe sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
agcolom committed Aug 2, 2012
1 parent b1b3a6d commit f16a7a3
Show file tree
Hide file tree
Showing 19 changed files with 1,140 additions and 5 deletions.
100 changes: 95 additions & 5 deletions entries/select.xml
Expand Up @@ -19,7 +19,8 @@
</select>
</code></pre>

<p>This will produce a basic select menu. The default styles set the width of the input to 100% of the parent container and stacks the label on a separate line.</p>
<p>This will produce a basic select menu. The default styles set the width of the input to 100% of the parent container and stacks the label on a separate line.
<iframe src="/resources/select/example1.html" style="width:100%;height:190px;border:0px"></iframe></p>


<h3>Mini version</h3>
Expand All @@ -36,7 +37,8 @@
&lt;/select&gt;
</code></pre>

<p>This will produce a select that a not as tall as the standard version and has a smaller text size.</p>
<p>This will produce a select that a not as tall as the standard version and has a smaller text size.
<iframe src="/resources/select/example2.html" style="width:100%;height:190px;border:0px"></iframe></p>

<h3>Field containers</h3>

Expand All @@ -52,9 +54,15 @@
&lt;/select&gt;
&lt;/div&gt;
</code></pre>

<p>The select input is now displayed like this:
<iframe src="/resources/select/example3.html" style="width:100%;height:190px;border:0px"></iframe></p>

<p>An example of a select with a long list of options:
<iframe src="/resources/select/example4.html" style="width:100%;height:590px;border:0px"></iframe></p>

<h3>Optgroups</h3>
<p>The following example organizes the options into <code>optgroup</code> elements. Support for this feature in mobile selects is a bit spotty, but is improving.</p>
<h3>Optgroups</h3>
<p>The following example organizes the options into <code>optgroup</code> elements. Support for this feature in mobile selects is a bit spotty, but is improving.</p>

<pre><code>
&lt;div data-role="fieldcontain"&gt;
Expand All @@ -80,6 +88,7 @@
&lt;/div&gt;
</code></pre>

<iframe src="/resources/select/example5.html" style="width:100%;height:390px;border:0px"></iframe>

<h3>Vertically grouped select inputs</h3>

Expand Down Expand Up @@ -117,14 +126,95 @@
&lt;/fieldset&gt;
&lt;/div&gt;
</code></pre>


<iframe src="/resources/select/example6.html" style="width:100%;height:390px;border:0px"></iframe>

<h3>Horizontally grouped select inputs</h3>
<p>Select inputs can also be used for grouped sets with more than one related selections. To make a horizontal button set, add the <code>data-type="horizontal"</code> to the fieldset. Note that the buttons which trigger the select will resize depending on the currently selected option’s value. Note that browsers without support for <code>display: inline-block;</code> will group the selects vertically, as above.</p>

<code>
&lt;fieldset data-role="controlgroup" data-type="horizontal"&gt;
</code>
<iframe src="/resources/select/example7.html" style="width:100%;height:190px;border:0px"></iframe>

<h3>Theming selects</h3>
<p>You can specify any jQuery Mobile button <code>data-</code> attribute on a select element, too. In this example, we're setting the theme, icon and inline properties:
<iframe src="/resources/select/example8.html" style="width:100%;height:190px;border:0px"></iframe>
</p>

<h2>Custom select menus</h2>
<p>The framework is capable of building a custom menu based on the <code>select</code> element's list of options. We recommend using a custom menu when multiple selections are required, or when the menu itself must be styled with CSS.</p>

<p>You can optionally use custom-styled select menus instead of the native OS menu. The custom menu supports disabled options and multiple selection (whereas native mobile OS support for both is inconsistent), adds an elegant way to handle placeholder values, and restores missing functionality on certain platforms such as <code>optgroup</code> support on Android (all explained below). In addition, the framework applies the custom button's theme to the menu to better match the look and feel and provide visual consistency across platforms. Lastly, custom menus often look better on desktop browsers because native desktop menus are smaller than their mobile counterparts and tend to look disproportionate.</p>

<p>Keep in mind that there is overhead involved in parsing the native select to build a custom menu. If there are a lot of selects on a page, or a select has a long list of options, this can impact the performance of the page, so we recommend using custom menus sparingly. </p>

<p>To use custom menus on a specific <code>select</code>, just add the <code>data-native-menu="false"</code> attribute. Alternately, this can also programmatically set the select menu's <code>nativeMenu</code> configuration option to <code>false</code> in a callback bound to the <code>mobileinit</code> event to achieve the same effect. This will globally make all selects use the custom menu by default. The following must be included in the page after jQuery is loaded but before jQuery Mobile is loaded.</p>


<pre><code>
$(document).bind('mobileinit',function(){
$.mobile.selectmenu.prototype.options.nativeMenu = false;
});
</code></pre>


<p>When the <code>select</code> has a small number of options that will fit on the device's screen, the menu will appear as a small overlay with a pop transition:
<iframe src="/resources/select/example9.html" style="width:100%;height:190px;border:0px"></iframe></p>

<p>When it has too many options to show on the device's screen, the framework will automatically create a new &quot;page&quot; populated with a standard <a href="listview">listview</a> for the options. This allows us to use the native scrolling included on the device for moving through a long list. The text inside the <code>label</code> is used as the title for this page.
<iframe src="/resources/select/example10.html" style="width:100%;height:590px;border:0px"></iframe></p>

<h3>Disabled options</h3>

<p>jQuery Mobile will automatically disable and style option tags with the <code>disabled</code> attribute. In the demo below, the second option &quot;Rush: 3 days&quot; has been set to disabled.

<iframe src="/resources/select/example11.html" style="width:100%;height:190px;border:0px"></iframe></p>

<h3>Placeholder options</h3>
<p>It's common for developers to include a &quot;null&quot; option in their select element to force a user to choose an option. If a placeholder option is present in your markup, jQuery Mobile will hide them in the overlay menu, showing only valid choices to the user, and display the placeholder text inside the menu as a header. A placeholder option is added when the framework finds:</p>
<ul>
<li>An option with no value attribute (or an empty value attribute)</li>
<li>An option with no text node</li>
<li>An option with a <code>data-placeholder="true"</code> attribute. (This allows you to use an option that has a value and a textnode as a placeholder option).</li>
</ul>

<p>You can disable this feature through the selectmenu plugin's <code>hidePlaceholderMenuItems</code> option, like this:</p>

<pre><code>
$.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
</code></pre>

<p>Examples of various placeholder options:
<iframe src="/resources/select/example12.html" style="width:100%;height:390px;border:0px"></iframe></p>

<h3>Multiple selects</h3>
<p>If the <code>multiple</code> attribute is present in your markup, jQuery Mobile will enhance the element with a few extra considerations:</p>

<ul>
<li>A header element will be created inside the menu and display the placeholder text and a close button.</li>
<li>Clicking on an item inside the overlay menu will not close the widget.</li>
<li>A ghosted, unchecked icon will appear adjacent to each unselected item. When the item is selected the icon will change to a checkbox. Neither icon will appear inside a single select box.</li>
<li>Once 2+ items are selected, a counter element with the total number of selected items will appear inside the button.</li>
<li>The text of each selected item will appear inside the button as a list. If the button is not wide enough to display the entire list, it is truncated with an ellipses.</li>
<li>If no items are selected, the button's text will default to the placeholder text.</li>
<li>If no placeholder element exists, the default button text will be blank and the header will appear with just a close button. Because this isn't a friendly user experience, we recommended that you always specify a placeholder element when using multiple select boxes.</li>
</ul>
<iframe src="/resources/select/example13.html" style="width:100%;height:390px;border:0px"></iframe>
<p>When a select is large enough to where the menu will open in a new page, the placeholder text is displayed in the button when no items are selected, and the <code>label</code> text is displayed in the menu's header. This differs from smaller overlay menus where the placeholder text is displayed in both the button and the header, and from full-page single selects where the placeholder text is not used at all.
<iframe src="/resources/select/example14.html" style="width:100%;height:590px;border:0px"></iframe></p>

<h3>Optgroup support</h3>
<p>If a select menu contains <code>optgroup</code> elements, jQuery Mobile will create a divider &amp; group items based on the <code>label</code> attribute's text:
<iframe src="/resources/select/example15.html" style="width:100%;height:390px;border:0px"></iframe></p>

<h2>Theming selects</h2>
<p>You can specify any jQuery Mobile button <code>data-</code> attribute on a select element, too. In this example, we're setting the theme, icon and inline properties:
<iframe src="/resources/select/example16.html" style="width:100%;height:190px;border:0px"></iframe></p>

<p>The <code>data-overlay-theme</code> attribute can be added to a select element to set the color of the overlay layer for the dialog-based custom select menus and the outer border of the smaller custom menus. By default, the content block colors for swatch "a"" will be used for the overlays.
<iframe src="/resources/select/example17.html" style="width:100%;height:190px;border:0px"></iframe></p>
<p><iframe src="/resources/select/example18.html" style="width:100%;height:590px;border:0px"></iframe></p>

<h3>Calling the select menu plugin</h3>
<p>The select menu plugin will auto initialize on any page that contains a select menu, without any need for a <code>data-role</code> attribute in the markup. However, you can directly call the select menu plugin on any selector, just like any normal jQuery plugin:</p>
Expand Down
39 changes: 39 additions & 0 deletions resources/select/example1.html
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<style>
html, body { padding: 0; margin: 0; }
html, .ui-mobile, .ui-mobile body {
height: 185px;
}
.ui-mobile, .ui-mobile .ui-page {
min-height: 185px;
}
.ui-content{
padding:10px 15px 0px 15px;
}
</style>
</head>

<body>
<div data-role="page" style="max-height:190px; min-height:190px;">
<div data-role="content" >
<label for="select-choice-0" class="select">Shipping method:</label>
<select name="select-choice-0" id="select-choice-0">
<option value="standard">Standard: 7 day</option>
<option value="rush">Rush: 3 days</option>
<option value="express">Express: next day</option>
<option value="overnight">Overnight</option>
</select>
</div>
</div>
</body>
</html>

87 changes: 87 additions & 0 deletions resources/select/example10.html
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<style>
html, body { padding: 0; margin: 0; }
html, .ui-mobile, .ui-mobile body {
height: 585px;
}
.ui-mobile, .ui-mobile .ui-page {
min-height: 585px;
}
.ui-content{
padding:10px 15px 0px 15px;
}
</style>
</head>

<body>
<div data-role="page" style="max-height:590px; min-height:590px;">
<div data-role="content" >
<div data-role="fieldcontain">
<label for="select-choice-3" class="select">Your state:</label>
<select name="select-choice-3" id="select-choice-3" data-native-menu="false">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
</div>
</div>
</body>
</html>

41 changes: 41 additions & 0 deletions resources/select/example11.html
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<style>
html, body { padding: 0; margin: 0; }
html, .ui-mobile, .ui-mobile body {
height: 185px;
}
.ui-mobile, .ui-mobile .ui-page {
min-height: 185px;
}
.ui-content{
padding:10px 15px 0px 15px;
}
</style>
</head>

<body>
<div data-role="page" style="max-height:190px; min-height:190px;">
<div data-role="content" >
<div data-role="fieldcontain">
<label for="select-choice-7" class="select">Shipping method:</label>
<select name="select-choice-7" id="select-choice-7" data-native-menu="false">
<option value="standard">Standard: 7 day</option>
<option value="rush" disabled="disabled">Rush: 3 days</option>
<option value="express">Express: next day</option>
<option value="overnight">Overnight</option>
</select>
</div>
</div>
</div>
</body>
</html>

64 changes: 64 additions & 0 deletions resources/select/example12.html
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<style>
html, body { padding: 0; margin: 0; }
html, .ui-mobile, .ui-mobile body {
height: 385px;
}
.ui-mobile, .ui-mobile .ui-page {
min-height: 385px;
}
.ui-content{
padding:10px 15px 0px 15px;
}
</style>
</head>

<body>
<div data-role="page" style="max-height:390px; min-height:390px;">
<div data-role="content" >
<div data-role="fieldcontain">
<label for="select-choice-4" class="select">Shipping method:</label>
<select name="select-choice-4" id="select-choice-4" data-native-menu="false">
<option></option>
<option value="standard">Standard: 7 day</option>
<option value="rush">Rush: 3 days</option>
<option value="express">Express: next day</option>
<option value="overnight">Overnight</option>
</select>
</div>

<div data-role="fieldcontain">
<label for="select-choice-5" class="select">Shipping method:</label>
<select name="select-choice-5" id="select-choice-5" data-native-menu="false">
<option>Choose one...</option>
<option value="standard">Standard: 7 day</option>
<option value="rush">Rush: 3 days</option>
<option value="express">Express: next day</option>
<option value="overnight">Overnight</option>
</select>
</div>

<div data-role="fieldcontain">
<label for="select-choice-6" class="select">Shipping method:</label>
<select name="select-choice-6" id="select-choice-6" data-native-menu="false">
<option value="choose-one" data-placeholder="true">Choose one...</option>
<option value="standard">Standard: 7 day</option>
<option value="rush">Rush: 3 days</option>
<option value="express">Express: next day</option>
<option value="overnight">Overnight</option>
</select>
</div>
</div>
</div>
</body>
</html>

0 comments on commit f16a7a3

Please sign in to comment.