#

Navigation Search

- Accordion
- AJAX Navigation
- Autocomplete
- Buttons
- Checkboxes
- Collapsibles
- Controlgroup
- Dialogs
- Fixed toolbars
- Flip switch toggle
- Footer toolbar
- Form elements
- Grids
- Header toolbar
- Icons
- Links
- Listviews
- Loader overlay
- Navbar
- Navbar, persistent
- Pages
- Panels New
- Popup
- Radio buttons
- Select
- Slider, single
- Slider, dual range New
- Table, column toggle New
- Table, reflow New
- Text inputs & textarea
- Transitions
- Collapsibles
- Dynamic collapsible
- Controlgroups
- Dynamic controlgroup
- Listviews
- Grid Listview
- Autodividers Linkbar
- Autodividers Selector
- Navigation
- Backbone and Require.js example
- Redirection with server-side support
- Panels
- Panel styling
- Open panel on swipe
- Popups
- Dynamic popup
- Popup with arrow
- Responsive Tables
- Reflow: Custom styles
- Reflow: Heading groups
- Reflow: Refresh method
- Column toggle: Customization options
- Column toggle: Heading groups
- Column toggle: Refresh method
- Column toggle demo: Phone comparison
- Sliders
- Tooltip extension
- Swipe
- Swipe to navigate
- Swipe to delete list item
- Forms
- Why won't my CSS styles apply correctly to a widget?
- Updating the value of enhanced form elements does not work.
- My HTML 5 inputs look different across devices and browsers.
- My range or search inputs are being change to number/text.
- Sometimes my custom select shows as a popup other times its a dialog.
- Disabling a button does not work.
- Controls in my fixed header or footer are not responding or behave erratically.
- Pages
- Why aren't my scripts and styles loading?
- Why isn't DOM ready working for my scripts?
- How do I load a page?
- Why is only the first page of my multi page document loaded?
- I'm trying to pass query params to a page but it's not working?
- I'm trying to pass information via the hash but it's not working?
- I'm trying to use the application cache but it's not working.
- Content injected into a page is not enhanced.
- Triggering create on injected HTML does not work.
- How can I stop JQM from auto-enhancing an element?
- How can I stop JQM from enhancing a block of elements?
- How do I control page titles?
- How do I load a page?
- Events
- How do I use touch and mouse events?
- Theme and styling
- How does theming work?
- Apps
- How do I need to configure PhoneGap/Cordova?

# Form elements

All form widgets begin with native form elements with rich HTML semantics that are enhanced to make them more attractive and finger-friendly.

## Markup conventions

When constructing forms to be used in jQuery Mobile, most of the standard guidelines used to create forms that submit via ordinary HTTP POST or GET still apply. Additionally, the `id` attributes of form controls need to be not only unique on a given page, but also unique across the pages in a site. This is because jQuery Mobile's single-page navigation model allows many different "pages" to be present in the DOM at the same time. You must be careful to use unique `id` attributes so there will be only one of each in the DOM. Be sure to pair them properly with `label` elements via the `for` attribute.

## Buttons

Buttons are core widgets in jQuery Mobile and are used within a wide range of other plugins. The button markup is flexible and can be created from links or form buttons. Learn more about buttons.

Link button

Inline buttons

Inline + icon Mini + theme icon only button

Horizontal grouped buttons

Add Delete More

## Sliders

Sliders are used to enter numeric values along a numeric continuum by dragging a handle or entering in a value. Learn more about sliders.

Slider:
Slider with fill and step of 50:
Slider with fill, mini, track theme:

## Range slider

Range sliders offer two handles to set a min and max value along a numeric continuum. Learn more about range sliders.

Rangeslider: Rangeslider:
Mini rangeslider: Mini rangeslider:

## Flip switch

Flip switches are used for boolean style inputs like true/false or on/off in a compact UI element. Learn more about flip switches.

Flip switch:
Mini flip switch:

## Checkboxes

Checkboxes are used to provide a list of options where more than one can be selected. Learn more about checkboxes.

Checkboxes, vertical controlgroup:
Cheetos Doritos Fritos Sun Chips
Checkboxes, mini, horizontal controlgroup:
b i u

## Radio buttons

Radio buttons are used to provide a list of options where only a single option can be selected. Learn more about radiobuttons.

Radio buttons, vertical controlgroup:
Cat Dog Hamster Lizard
Radio buttons, mini, horizontal controlgroup:
List Grid Gallery

## Selects

The select menu is used to offer a list of options in a compact picker. Ours is based on a native select element, which is hidden from view and replaced with a custom-styled select button. Tapping it opens the native menu or a custom styled version. Learn more about selects.

Select, native menu
Mini select, inline
Custom select menu:
Multi-select with optgroups, custom icon and position:

## Text inputs & Textareas

Text inputs and textareas are coded with standard HTML elements, then enhanced by jQuery Mobile to make them more attractive and useable on a mobile device. Learn more about text inputs and textareas.

Text input:
Textarea:
Number + [0-9]* pattern:
Date:
Tel:
Search Input:
File:
Password:

See the form gallery for more form element examples.

## Accessibly hidden labels

For the sake of accessibility, jQuery Mobile requires that all form elements be paired with a meaningful `label`. To hide labels in a way that leaves them visible to assistive technologies — for example, when letting an element's `placeholder` attribute serve as a label — apply the helper class `ui-hidden-accessible` to the label. View more examples of accessibly hidden labels. In case you use a field container you can use class `ui-hide-label` on the element with `data-role="fieldcontain"` to hide the label or legend.

Text Input:

## Disabling form elements

All jQuery Mobile widgets can be disabled in the markup by adding the standard `disabled` attribute to the element, just like you would with native controls. Each form widget also has standard `disable` and `enable` methods that are documented with each form widget. View more examples of disabled form elements.

Text Input:

Note that you can disable buttons created from `button` or `input`-based markup, but not links with a role of button. Links don't have a parallel disabled feature in HTML, but if you need to disable a link-based button (or any element), it's possible to apply the disabled class `ui-disabled` yourself with JavaScript to achieve the same effect.

## Fieldcontainer groupings

To improve the styling of labels and form elements on wider screens, wrap a `div` or `fieldset` with the `data-role="fieldcontain"` attribute around each label/form element. This framework aligns the input and associated label side-by-side, and breaks to stacked block-level elements below ~448px. The framework will also add a thin bottom border to act as a field separator. See more examples of fieldcontainer groupings.

Text Input:
Native select:

## 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. 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 options, methods, and events listed on each form plugin's documentation page for details.

## Initializing groups of dynamically-injected form elements

If you should generate new markup client-side or load in content via AJAX and inject it into a page, you can trigger the `create` event to handle the auto-initialization for all the plugins contained within the new markup. This can be triggered on any element (even the page div itself), saving you the task of manually initializing each plugin (see below).

For example, if a block of HTML markup (say a login form) was loaded in through AJAX, trigger the create event to automatically transform all the widgets it contains (inputs and buttons in this case) into the enhanced versions. The code for this scenario would be:

    $( ...new markup that contains widgets... ).appendTo( ".ui-page" ).trigger( "create" );

## Refreshing form elements

In jQuery Mobile, some enhanced form controls are simply styled (inputs), but others are custom controls (selects, sliders) built from, and kept in sync with, the native control. To programmatically update a form control with JavaScript, first manipulate the native control, then use the `refresh` method to tell the enhanced control to update itself to match the new state. Here are some examples of how to update common form controls, then call the `refresh` method:

#### Checkboxes:

    $( "input[type='checkbox']" ).prop( "checked", true ).checkboxradio( "refresh" );

#### Radios:

    $( "input[type='radio']" ).prop( "checked", true ).checkboxradio( "refresh" );

#### Selects:

    var myselect = $( "#selectfoo" );
    myselect[0].selectedIndex = 3;
    myselect.selectmenu( "refresh" );

#### Sliders:

    $( "input[type='range']" ).val( 60 ).slider( "refresh" );

#### Flip switches:

They use the slider widget.

    var myswitch = $( "#selectbar" );
    myswitch[ 0 ].selectedIndex = 1;
    myswitch.slider( "refresh" );

## 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>
    	<option value="b">B</option>
    	<option value="c">C</option>
    </select>

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

Alternately you can use the `data-enhance="false"` data attribute on a parent element with `$.mobile.ignoreContentEnabled` set to true. Beware though, this will incur a performance penalty for each and every element in the page that would otherwise be enhanced as jQuery Mobile must traverse the set of parents to look for those elements.

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 and appearance of the menu itself and benefit from the visual augmentation of the select button by jQuery Mobile, you can set `$.mobile.selectmenu.prototype.options.nativeMenu` to true in a `mobileinit` callback as a global setting or use `data-native-menu="true"` on a case by case basis.

## File Inputs + AJAX

Using a multipart form with a file input is not supported by AJAX. In this case you should decorate the parent form with `data-ajax="false"` to ensure the form is submitted properly to the server.