HTML5 Forms

In addition to new tag elements in HTML5 the input element has been extended with new types and attributes. Although these changes are not fully supported across all browsers they can still be added if desired to your existing websites.

New input attributes

Placeholder Text

It is common practice to include placeholder or default text in form input fields. In most cases they simply describe what data should be entered and once a user clicks or focuses on the field the value is displayed. HTML5 specifications has added the placeholder attribute to input elements so that browsers will perform this function instead of having it performed by JavaScript. However until it is supported by all browsers you will still need to use JavaScript.

<form>
    <input name="query" placeholder="Search" />
</form>

Auto Focus

You may in your websites be using a piece of JavaScript to focus a form field after a page has loaded. To make this task easier the autofocus attribute has been added.

<form>
    <input name="name" autofocus />
</form>

New input types

The greatest thing about the input element is that if it doesn’t recognize the type (e.g. the browser doesn’t support the type) then it will default back to a text input field. That means that if you want to use any of the new input types like search and email then you can do so without worrying about missing form fields.

Search Input

In HTML5 it was decided to add a search type input. As you all know in your web pages you typically use a normal text type input for your search forms. However it was decided that the new search type should be added so browsers could add additional functionality to them to match the browsers search functionality. What this means is that each browser can do what they want with the field including changing the style to match the browser’s search so that it no longer is consistent with the rest of your web page.

<form>
    <input name="query" type="search" />
</form>

URL & EMAIL Input

Both URLs and emails are strings that conform to respective Internet Standards. To make validation consistent and easier for developers the url and email type input elements have been added. The purpose of these fields is to verify and restrict the inputted data so only valid information is sent back to the server. However this validation would be performed at the browser level and if you are verifying other fields you will end up having to manage multiple error messages to the user which could be confusing to them.

<form>
    <input name="email" type="email" />
    <input name="website" type="url" />
</form>

Sliders and Spinboxes

Ever wanted to have simple easy to use slidebars or spinboxes when a user is inputting number values. In HTML5 your wish has been granted with the number and range input types. These elements allow you to set a minimum and maximum value as well as a step value for how it should be incremented. Again allowing the browser to display their version of sliders and spinbox controls and you not having to implement a JavaScript library to get your desired elements.

<form>
    <input type="number" min="8" max="29" step="1" value="12" />
    <input type="range" min="0" max="10" step="2" value="6" />
</form>

Calendar and Color Pickers

Commonly you will find yourself requesting that a user input a date or time and to handle this you will most likely include a JavaScript calendar to get your desired date picker. Similarly to number inputs, HTML5 adds support for input of various date types including month, date and time. These elements if supported by the browser would present a calendar interface for selecting a valid value. Less common but also specified is the color picker element defined by type color, however at this time no current browser supports the element.

<form>
    <input type="color" />
    <input type="date" />
    <input type="time" />
</form>

HTML5 raises some developer complications and in my opinion is incomplete. The specifications outline the details on common elements currently created by JavaScript, however they do not specify how those objects are to be rendered. What this means is that it is up to the browser on how they are displayed and are no longer in the control of the designer/developer. In addition it introduces the concept of browser validation of input yet once again it doesn’t specify how the browser should handle the validation or how the designer/developer can tap into the validation. With complicated forms it is often the case that input is validated not only for standards but for required fields or custom data values, by including the new HTML5 elements you know have to worry about validation errors from your own scripts but also the browser and the multiple feedback could be confusing to your Users.

I understand that HTML5 is taking the first steps in expanding the common functionality of the web and it’s browser, however to make these new elements a viable choice for web developers/designers more specifications need to be detailed in how a browser is to behave. For example if you have a web form that is styled to match your site and the browser displays search input that doesn’t match your site then it won’t be used, same with calendars and color pickers. A good start definitely but don’t expect to see these elements commonly used for a while to come.

Resources

, , , , , , , , , , , , ,

When querying or working with data based on datetime, date, or time values Sybase has a group of Date functions available to help perform arithmetic operations.  These functions include GETDATE, MONTH, YEAR, DATEADD, and DATEDIFF.

To help illustrate some of these functions lets assume we have the following ITEM, ORDERS, and ORDERS_ITEM tables that contains the following columns and data.

ITEM
ID NAME PRICE
1 Crystal Vase 30.00
2 White vase 5.00
3 Silver Vase 15.00
4 Tall Vase 12.00
5 Gold Vase 25.00
6 Blue Glass Vase 20.00
7 Pewter Vase 11.00
ORDERS
ID BUY_DATE
1 12/13/2008
2 12/17/2008
3 12/24/2008
4 1/02/2009
5 1/05/2009
6 1/15/2009
7 2/03/2009
ORDER_ITEM
ORDER_ID ITEM_ID QUANTITY
1 3 2
1 1 6
2 1 7
3 4 5
3 3 8
3 7 7
4 6 10
5 5 6
6 3 3
7 2 3
7 7 1

How to obtain the current date and or time

The GETDATE function is used to get the current system date and time. Lets assume that we want to obtain a report of the orders that were made today, to do so we would want to compare the ORDERS.BUY_DATE column with the current date. As our table is not storing the time and only the date we would make use of the current_date function to only get the date (likewise the current_time function returns the time).

SELECT * FROM ORDERS WHERE BUY_DATE = CURRENT_DATE()

Assuming today’s date was February 3rd, 2009 we would have the following results:

ID BUY_DATE
7 2/03/2009

Modifying the time using DATEADD

Now that we know how to get the current date and time in a Sybase T-SQL, lets assume we have a report that runs every day in the morning that reports the orders that were made the previous day. To do this we can modify our previous example to compare the date against the current date – 1 day. Sybase provides the DATEADD function to modify the date.

SELECT * FROM ORDERS
WHERE BUY_DATE = DATEADD( dd, -1, CURRENT_DATE() )

The DATEADD function takes 3 parameters the part of date to be modified, value to modify by, and the date to be modified.
Assuming today’s date was February 4th, 2009 we would have the same results as the previous example

ID BUY_DATE
7 2/03/2009

Utilizing the month and year parts of a Date

Sybase provides two convenient methods for obtaining the month or year part of a Date. These functions can be used to query data for a particular period of time.  Both the MONTH, and YEAR functions take a single parameter and that is the date for which the month or year should be returned.

For our first example lets assume we want to know which items and how many were sold for the current month. To do this we will need to join the ORDERS and ITEM tables based on the ORDERS_ITEM linking table and return the sum of the quantity that were sold for each order.

SELECT i.NAME, SUM(oi.QUANTITY) AS NUM_SOLD
FROM ORDERS o
  JOIN ORDER_ITEM oi ON o.ID = oi.ORDER_ID
  JOIN ITEM i ON i.ID = oi.ITEM_ID
WHERE MONTH (o.BUY_DATE) = MONTH( CURRENT_DATE() )
GROUP BY i.NAME

Running this query assuming that the current date is the last day of December, 2008 would return the following results.

NAME NUM_SOLD
Silver Vase 10
Crystal Vase 13
Tall Vase 5
Pewter Vase 7

Sybase provides additional Date functions besides those mentioned above to familiarize yourself with them on I suggest accessing their online manual which can be accessed under References.

References

, , , , ,