Tutorial 4 : jQuery Vaizr primer
If you want to go to the previous tutorial click here
If you want to go to the next tutorial click here
You can download the tutorial resources here
Introduction
Understanding jQuery begins with an understanding of JavaScript. Sometimes jQuery is treated as an independent language that can be used instead of JavaScript. Although jQuery contains many features associated with programming languages, it is best thought of as a library that enhances JavaScript in specific situations. For this reason, JavaScript has been introduced before jQuery.
Before understanding jQuery however, it is worth taking a brief look at the Document Object Model (DOM), since jQuery is primarily a library for dealing with the DOM in a browser independent manner.
Selection
The first thing we are going to do with Vaizr is select items from the screen.
Selecting elements obviously has no intrinsic value in its own right; we are eventually going to do something with these elements. A Vaizr selection will return zero or more Objects from the screen which contains details on the requested field name.
In order to perform a selection of an object, simply call the following function with the current screen items and the name of the field used in the screen:
> For a field :
$.alfa.DlgBlocks.getFieldFromPage(pageItems, 'due_date')
> For a button :
$.alfa.DlgBlocks.getButton(pageItems, 'search')
> For a table :
$.alfa.DlgBlocks.getTable(pageItems, 'search_result_table')
The pageItems is a list of objects displayed in the screen. The are usually available with all the pre/post hooks provided in the screen. The second arguement ('due_date' in the above example) is the name of the item referred to in the screen.
The above line will provide an object with the following properties:
- text field (date, checkbox , large-string)
- Id
- type
- value
- Lov field
- Id
- type
- value
- valuefield
- use_cache
- title
- size
- label
- displayfields
- editfields
- service
- dwr
- parameters
- lov
- Button
- Id
- action
- icon
- Table
- type
- name
- id
- data
- columns
- count
- customColumns
- displayLength
- fnPaging
- oncontextmenu
- ondblclick
- onkeys
- paginationType
- rows
- selectMode
- sortMode
- tableHeight
- totalCount
- totalWidth
Events
The next aspect of jQuery to understand is events. When writing web applications, the application will need to respond to events initiated by the user.
These events may be any of the following:
- Clicking a link or button.
- Double clicking a button or link.
- Changing the value in a text field.
- Pressing a particular key inside an input field.
- Selecting an option in a select list.
- Focusing on an input field.
- Hovering the mouse over an element.
In addition to these user-initiated events, the application may wish to respond to browser-initiated events such as:
- The document has finished loading.
- The web browser window is resized.
- An error occurring.
This section will first explain the ways event listeners can be registered, and will then look at some of these events in detail.
Before beginning, we will add the examples above permanently to the tasks.html page. In order to do this, add the following block immediately before the closing