HTML form elements in jQuery Mobile are applied styles with CSS, making them attractive and easy to use.
jQuery Mobile has following form controls:
• Text Inputs
- Radio Buttons
- Search Inputs
- Checkboxes
- Sliders
- Select Menus
- Flip Toggle Switches
The
<form>
element in jQuery Mobile forms should possess a method and an attribute
action
. Every element of the form must be given a unique attribute
"id"
.The pages in the site should have id's. The reason is
single page navigation model of jQuery Mobile allows the navigation of multiple "pages" to be presented at the same time. Every element of the jQuery Mobile Forms should have a
label
. In order to match with element id set the
"for"
attribute of the label.
Eg:
[html]
<label for="fname">First name:</label>
<input type="text" name="fname" id="fname">
[/html]
To give an idea about the input field, a placeholder can be specified.
Eg:
[html]<label for="fname">First name:</label>
<input type="text" name="fname" id="fname" placeholder="First name...">[/html]
Label is hidden by using the class
"ui-hidden-accessible"
. This is used mostly when there is requirement to hide the place holder attribute of the element to serve as the label.
Eg:
[html]<label for="fname" class="ui-hidden-accessible" "="">First name:</label>
<input type="text" name="fname" id="fname" placeholder="First name...">[/html]
To use "clear button" that clears the contents of the input box, add the
data-clear-btn="true"
attribute.
Eg:
[html]<label for="fname">First name:</label>
<input type="text" name="fname" id="fname" data-clear-btn="true">[/html]
Any <input> element can have the "clear button", except the <textarea>.