html5 and css3

40
HTML5 AND CSS3 Neal Stublen [email protected]

Upload: diallo

Post on 22-Feb-2016

36 views

Category:

Documents


0 download

DESCRIPTION

Neal Stublen [email protected]. HTML5 and CSS3. Chapter 4 Forms. Improvements. New form elements Assist with validation Consistency across sites Changes reduce the need for common JavaScript improvements. Sign Up Form. The HTML Herald has a sign up form that collects user data. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: HTML5 and CSS3

HTML5 AND CSS3Neal Stublen

[email protected]

Page 2: HTML5 and CSS3

CHAPTER 4

FORMS

Page 3: HTML5 and CSS3

Improvements New form elements Assist with validation Consistency across sites Changes reduce the need for common

JavaScript improvements

Page 4: HTML5 and CSS3

Sign Up Form The HTML Herald has a sign up form

that collects user data.

Page 5: HTML5 and CSS3

Element Attributes

Page 6: HTML5 and CSS3

The required Attribute An empty or invalid field will prevent the

form from being submitted Simply add a “required” attribute

requiredrequired=“required”aria-required=“true”

Require name, email, password, start date

Page 7: HTML5 and CSS3

Styling required elements The :required pseudo-class can be used to style form

elements

input:required { background-image: url(required.png);}input:invalid { background-image: url(invalid.png);}input:valid { background-image: url(valid.png);}

Page 8: HTML5 and CSS3

Default element styles Default element styles may differ

between browsers (Firefox 4) Firefox 4 applies a red shadow to invalid

elements Disable this style:

:invalid { box-shadow: none; }

Page 9: HTML5 and CSS3

Backward Compatibility Older browsers might not support

the :required pseudo-class Use the attribute selector

input:required,input[required] { background-image: url(…);}

Page 10: HTML5 and CSS3

The placeholder attribute Allows a short hint inside the form

element Text disappears when the element gains

focus and reappears when the element loses focus if no data has been entered

Add placeholder text for website and start date

Page 11: HTML5 and CSS3

JavaScript placeholders JavaScript can be used in browsers that

don’t support the placeholder attribute

Page 12: HTML5 and CSS3

The pattern attribute Constrains input to an expected pattern Regular expression syntax “title” attribute can be used to explain

requirements

Require passwords of at least 6 characters

\${6,}

Page 13: HTML5 and CSS3

The disabled attribute Disabling an element prevents user

input or changing an element’s value Disabling a fieldset disables all elements

within the fieldset Disabled elements are not submitted

with the form JavaScript can disable the submit button

until all fields are filled out Use the :disabled pseudo-class

Page 14: HTML5 and CSS3

The readonly attribute Similar to disabled – not editable Values are submitted with the form Reveals to the user data that’s being

collected, but ensures it hasn’t been changed

Page 15: HTML5 and CSS3

The multiple attribute Applies to the select, email and file

elements Select more than one file Specify multiple email addresses

separated by commas (or spaces)

Page 16: HTML5 and CSS3

The form attribute Not the form element Associates an element or fieldset with a

form, though it’s not nested within the form element

Page 17: HTML5 and CSS3

The autocomplete attribute Dropdown appears when the user

begins typing For password fields, allows the browser

to save the password Defaults to being “on”, set to “off” to

disableDisable for sensitive data

Page 18: HTML5 and CSS3

The datalist element Provides a list of autocomplete

suggestions Associated with an element using the list

attribute on the inputOne datalist can be attached to multiple

input elements

Page 19: HTML5 and CSS3

The autofocus attribute Specifies an element that should receive

focus as soon as the page loads Only specified on a single element

The name element will receive the initial focus

Page 20: HTML5 and CSS3

New Form Input Types

Page 21: HTML5 and CSS3

Pre-HTML5 button checkbox file hidden image password radio reset submit text

Page 22: HTML5 and CSS3

Search “search” specifies a text input control

that is used for search terms Stylistically distinct from text input

elements

Page 23: HTML5 and CSS3

Email Addresses “email” specifies one or more email

addresses Mobile devices can display a keyboard

customized for email address entry Browsers can validate the input looks like

an email address

Require an email address in the email field

Page 24: HTML5 and CSS3

URLs “url” specifies a web address Mobile devices can display a keyboard

customized for web address entry Browsers can validate the input looks

like a web address

Require a web address for the web site field

Page 25: HTML5 and CSS3

Telephone Numbers “tel” specifies a telephone number placeholder and pattern attributes can

provide instruction and validation, but the browser will not validate the format

Page 26: HTML5 and CSS3

Numbers “number” specifies numeric input Displays a “spinner” box to adjust the

value min and max attributes limit the range of

acceptable values The step attribute provides the bump

value for the spinner buttons Mobile devices may display a number

touchpad instead of a full keyboard

Page 27: HTML5 and CSS3

Ranges “range” specifies the use of a slider

control min, max, and step attributes control the

range and steps for the slider Similar to a number field, but lacks

necessary precisionCustomer satisfaction survey

Default value is the midpoint of the slider

Page 28: HTML5 and CSS3

Colors “color” specifies a color value field Generates a hexidecimal color value

#FF3300

Page 29: HTML5 and CSS3

Dates and Times “date”, “datetime”, “date-time-local”,

“month”, “time” and “week” specify a time valueISO 8601 standardyyyy-mm-ddThh:mmZ (datetime)yyyy-mm (month)yyyy-W01 to yyyy-W52 (week)

Change the startdate field

Page 30: HTML5 and CSS3

Non-supporting Browsers Any unsupported fields appear as text

fields placeholder text can be used to indicate

what content should be entered

Page 31: HTML5 and CSS3

New Form Controls

Page 32: HTML5 and CSS3

The output element output element displays a calculated

value Typically updated using JavaScript

Shopping cart total

Page 33: HTML5 and CSS3

New Form Attributes

Page 34: HTML5 and CSS3

The novalidate attribute Allows use of validation attributes on

fields (e.g. required, pattern) without actually performing validation before submitting a formPerhaps because you’re going to perform

your own validation

Page 35: HTML5 and CSS3

The action attribute No longer required Defaults to the current page

Page 36: HTML5 and CSS3

The autocomplete attribute Applies the autocomplete attribute to all

elements within the form Can be overridden on individual

elements

Page 37: HTML5 and CSS3

Form Element Changes

Page 38: HTML5 and CSS3

Multilevel select menus Specifying an optgroup as the child of

another optgroup will create a multilevel select menu

Page 39: HTML5 and CSS3

textarea Changes Formerly the rows and cols attributes

controlled the size of the field Size should now be specified using CSS wrap attribute inserts line breaks into

submitted inputsoft – submit line breaks entered by the userhard – submit line breaks created by

wrapping text in the browser

Page 40: HTML5 and CSS3

Form Validation Warning Form content can be validated in the web

browser Form content still must to be validated on

the server Why?

When your server receives your form’s input, it may not have come from your web page

Browser validation only speeds things up for the user