IT tutorials
 
Mobile
 

Mobile Web Apps : Quick Wins (part 2) - Form Field Attributes

11/15/2011 4:02:21 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Form Field Attributes

With our links all polished up, let’s turn to forms. HTML5 drags the basic form into the future with a quiver of shiny new input types and form attributes, which are well-supported on the current crop of mobile devices.

The HTML5 <placeholder> attribute of an input field will populate the field with a user prompt, which disappears when the user focuses on it. This is commonly used to avoid the need for a field label, or to offer additional help text to the user:

listing 5. ch4/06-links-forms.html (excerpt)
<fieldset>
<label for="name">
<span>Who</span>
<input type="text" name="name" placeholder="Star's name"/>
</label>
<label for="tags">
<span>Tags</span>
<input type="text" name="tags" placeholder="Tag your sighting"/>
</label>
</fieldset>

The iPhone’s keyboard tries to help out users by capitalizing the first letter in a form field. Most of the time, this is what you want—but not always; for example, in the tags field in our sample form. The iPhone will also attempt to correct words it fails to recognize, which can become a problem for our celebrity name field. These features can be disabled via the <autocorrect> and <autocapitalize> attributes:

listing 6. ch4/06-links-forms.html (excerpt)
<fieldset>
<label for="name">
<span>Star</span>
<input type="text" autocorrect="off" placeholder="Star's name"/>
</label>
<label>
<span>Tags</span>
<input type="text" autocapitalize="off" placeholder="Tag your sighting"/>
</label>
</fieldset>


Note that these attributes are nonstandard, in that they’re not in the HTML specification—at least for now.


Tip:

Turn off the Automagic

If the majority of your form’s fields require these attributes, you can also add them to the <form> tag itself, to apply them by default to all fields in that form. You can then override this setting on any given field as required.


Another HTML5 feature that’s useful for mobile sites is the addition of a number of new input types. Beyond the traditional type="text", HTML5 provides email, number, url, date, and even color inputs. These will all display as simple text fields on most browsers, but the iPhone cleverly provides appropriate keyboards for the data in question—for example, including shortcut keys for @ and . (period) when you use type="email". For type="number", it will provide a number pad instead of a traditional keyboard, as shown in Figure 2. The BlackBerry browser even provides date and color pickers for date and color input types.

Figure 2. A numeric keypad appears when focusing a number input on the iPhone


Here’s an example of these input types in action:

listing 7. ch4/06-links-forms.html (excerpt)
<label>
<span>Tags</span>
<input type="text" autocapitalize="off" placeholder="Relevant tags">
</label>
<label>
<span>Number of celebs</span>
<input type="number" placeholder="Number of celebs">
</label>
<label>
<span>Tags</span>
<input type="email" placeholder="Your email address">
</label>

Support for all these features is inconsistent, so you’ll need to test your target devices. The good news is that even when support is lacking, the app won’t appear broken. Unsupported input types will simply behave as regular text fields, and users will be none the wiser.

Because the iPhone was the first to market, many of the iOS proprietary tricks have wide support on other devices; yet, not everyone wants to implement a competitor’s features! Thankfully, support for the HTML5 standard is growing, and that should trickle down to all the big mobile players soon.
 
Others
 
- Mobile Web Apps : Quick Wins (part 1) - Nifty Links
- iPhone Developer : Using Creative Popping Options
- iPhone Developer : Navigating Between View Controllers
- iOS SDK : Basic SQLite Database Manipulation (part 3) - SQLite Binding, Inserting, Updating, and Deleting
- iOS SDK : Basic SQLite Database Manipulation (part 2) - Select
- iOS SDK : Basic SQLite Database Manipulation (part 1) - Opening the Database, Statements, Preparing Statements, and Executing Statements
- The Anatomy of a Mobile Site : PRIMARY SITE CONTENT (part 3) - Forms
- The Anatomy of a Mobile Site : PRIMARY SITE CONTENT (part 2) - Embedding Images and Media
- The Anatomy of a Mobile Site : PRIMARY SITE CONTENT (part 1) - Text, Typography& Pagination
- iPad Does Not Show Up in iTunes & Synchronization Problems
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us