diff --git a/docs/forms/docs-forms.html b/docs/forms/docs-forms.html index df42b651..11b429f8 100755 --- a/docs/forms/docs-forms.html +++ b/docs/forms/docs-forms.html @@ -1,15 +1,15 @@ - - + + - - jQuery Mobile Docs - Forms - + + jQuery Mobile Docs - Forms + - - + +
@@ -18,13 +18,13 @@
- +

jQuery Mobile provides a complete set of finger-friendly form elements that are based on native HTML form elements.

- +

Form structure

- +

All forms should be wrapped in a form tag that has an action and method that will handle the form data processing on the server.

- + <form action="form.php" method="post"> ... @@ -37,10 +37,10 @@

Auto-initialization of form elements

By default, jQuery Mobile will automatically enhance certain native form controls into rich touch-friendly components. This is handled internally by finding form elements by tag name and running a plugin method on them, so for instance, a select element will be found and initialized with the "selectmenu" plugin, while an input element with a type="checkbox" will be enhanced with the "checkboxradio" plugin. Once initialized, you can address these enhanced components programmatically through their jQuery UI widget API methods (see documentation on available methods here: Form Plugin Methods).

- +

Preventing auto-initialization of form elements

If you'd prefer that a particular form control be left untouched by jQuery Mobile, simply give that element the attribute data-role="none". For example:

-
				
+	

 <label for="foo">
 <select name="foo" id="foo" data-role="none">
 	<option value="a" >A</option>
@@ -48,34 +48,36 @@
 	<option value="c" >C</option>
 </select>
 
- - + +

Or, if you'd like to prevent auto-initialization without adding attributes to your markup, you can customize the selector that is used for preventing auto-initialization by setting the page plugin's keepNative option (which defaults to "[data-role="none"]. Be sure to configure this option inside an event handler bound to the mobileinit event, so that it applies to the first page as well as subsequent pages that are loaded.


 $(document).bind('mobileinit',function(){
 	$.mobile.page.prototype.options.keepNative = "select, input.foo, textarea.bar";
-});	
+});
 		
- + +

One special case is that of selects. The above sample will prevent any and all augmentation from taking place on select elements in the page if select is included. If you wish to retain the native performance, look/feel of the menu itself and benefit from the visual augmentation of the select button by jQuery Mobile you can set $.mobile.nativeSelectMenu to true in a mobileinit callback as a global setting or use data-native="true" on a case by case basis.

+

Dynamic form layout

In jQuery Mobile, all form elements are designed to be a flexible width so they will comfortably fit the width of any mobile device. One optimization built into the framework is that we present labels and form elements differently based on screen width.

-

If a page is fairly narrow (~480px), the labels are styled as block-level elements so they will stack on top of the form element to save horizontal space.

+

If a page is fairly narrow (~480px), the labels are styled as block-level elements so they will stack on top of the form element to save horizontal space.

On wider screens, the labels and form elements are styled to be on the same line in a 2-column layout to take advantage of the screen real estate.

Field containers

- +

To improve the styling to labels and form elements on wider screens, we recommend wrapping a div or fieldset with the data-role="fieldcontain" attribute around each label/form element. The framework will add a thin vertical bottom border on this container to act as a field separator and visually align the label and form elements for quick scanning.

-
				
+

 <div data-role="fieldcontain">
 	...label/input code goes here...
 </div>
 
- - + +
- \ No newline at end of file + diff --git a/docs/forms/forms-selects.html b/docs/forms/forms-selects.html index de34caa4..b1132b54 100644 --- a/docs/forms/forms-selects.html +++ b/docs/forms/forms-selects.html @@ -1,15 +1,15 @@ - - + + - - jQuery Mobile Docs - Forms - + + jQuery Mobile Docs - Forms + - - + +
@@ -18,19 +18,19 @@
- +

Select menus

- +

The select menus are driven off native select elements, but the native selects are hidden from view and replaced with more style-friendly markup. The replacement buttons and menus are ARIA-enabled and are keyboard accessible on the desktop as well.

When clicked, if the menu has room it will appear as an overlay listbox, but if there are too many options to fit in the window without scrolling, the page content is wrapped in a div and hidden, and the menu is appended as a whole new page. This lets us take advantage of native scrolling while the menu is in use.

- +

To add a select widget to your page, start with a standard select element populated with a set of option elements. Set the for attribute of the label to match the ID of the select so they are semantically associated. Wrap them in a div with the data-role="fieldcontain" attribute to help visually group it in a longer form.

- +

The framework will find all select elements and automatically enhance them into the custom select menus.

-
	
+

 <div data-role="fieldcontain">
 	<label for="select-choice-1" class="select">Choose shipping method:</label>
 	<select name="select-choice-1" id="select-choice-1">
@@ -41,7 +41,7 @@
 	</select>
 </div>
 
- +

If there is a small number of options that will fit on the device's screen, it will appear as a small overlay with a pop transition.

@@ -117,7 +117,15 @@

Option to use native menus

The custom select menus add the ability to theme the select and provide visual consistency across platforms In addition, it fixes over some missing functionality on certain platforms: optgroup support on Android, multi-select capability on WebOS, and adds an elegant way to handle placeholder values (explained below).

-

However, there is overhead involved in parsing the native select to build a custom menu and if the number of selects or options within are fairly large, this can impact the performance of the page. By adding the data-native="true" attribute to the select, the framework will use the browesr's native select menu when the select button is clicked. Because this option doesn't use any of the custom menu parsing and menu generation logic, it is significantly faster than the custom menu version.

+

However, there is overhead involved in parsing the native select to build a custom menu and if the number of selects or options within are fairly large, this can impact the performance of the page. By adding the data-native="true" attribute to the select, the framework will use the browser's native select menu when the select button is clicked. Because this option doesn't use any of the custom menu parsing and menu generation logic, it is significantly faster than the custom menu version.

+ +

You can also set the global configuration $.mobile.nativeSelectMenus to true in a callback bound to the mobileinit event to achieve the same effect. The following must be included in the page after jQuery is loaded but before jQuery Mobile.

+ +
+$(document).bind('mobileinit',function(){
+	$.mobile.nativeSelectMenus = true;
+});
+
@@ -174,9 +182,7 @@
- - - +

Placeholder options

It's common for developers to include a "null" 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:

    @@ -184,17 +190,17 @@
  • An option with no text node
  • An option with a data-placeholder="true" attribute. (This allows you to use an option that has a value and a textnode as a placeholder option).
- +

You can disable this feature through the selectmenu plugin's hidePlaceholderMenuItems option, like this:

 	
 $.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
 	
 	
- +

Here's a demo of various placeholder options:

- - + +
-
- - +
+ +
- - + +
- +

Disabled options

jQuery Mobile will automatically disable and style option tags with the disabled attribute. In the demo below, the second option "Rush: 3 days" has been set to disabled.

@@ -242,7 +248,7 @@ $.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
- +

Optgroup support

If a select menu contains optgroup elements, jQuery Mobile will create a divider & group items based on the label attribute's text:

@@ -262,11 +268,11 @@ $.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false; - - + +

Multiple selects

If the multiple attribute is present in your markup, jQuery Mobile will enhance the element with a few extra considerations:

- +
  • A header element will be created inside the menu and display the placeholder text and a close button.
  • Clicking on an item inside the overlay menu will not close the widget.
  • @@ -276,7 +282,7 @@ $.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
  • If no items are selected, the button's text will default to the placeholder text.
  • 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.
- +
- +

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 label 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.

- +
- +

Data attribute support

-

You can specify any jQuery Mobile button data- attribute on a select element too. In this example, we're setting the theme, icon and inline properties though data- attributes.

- +

You can specify any jQuery Mobile button data- attribute on a select element too. In this example, we're setting the theme, icon and inline properties though data- attributes.

+