|
Expanding The API
One of the key features of qForms is its expandable architecture. qForms was designed to
be easily expanded to meet specific needs of a project or just to fit your organziation.
Expansion methods are creating by attaching new prototypes to the existing constructors. In
order to do that, you'll need to know the name of each constructor and what it does.
qForm Constructor
The qForm constructor is used to create new qForm objects. You can add a new qForm prototype,
with the following syntax:
qForm.prototype.methodName = functionName;
(Where methodName is the name of the new method and functionName is
the name of the function to use.)
Field Constructor
The Field constructor is used to create new Field objects and is called automatically
for each field in a form whenever the qForm constructor is called. You can add a new
Field prototype, with the following syntax:
Field.prototype.methodName = functionName;
(Where methodName is the name of the new method and functionName is
the name of the function to use.)
Creating The Prototype Functions
When creating functions to use as the new methods, you'll have access to a special
object called "this". The this object is a pointer to the initialized
constructor. For example, when creating a new method for the "Field" constructor,
this.getValue() would return the value of the field the method was attached
to. For example, to create a method will set the specified field to today's date,
you'd use the following:
function __setToday(){
dToday = new Date();
var today = (dToday.getMonth() + 1) + "/";
today += dToday.getDate() + "/" + dToday.getYear();
this.setValue(today);
}
Field.prototype.setToday = __setToday;
We now have a new method we can use on our forms. For example, to set the field
"Date" to today's date, we simple call our new setToday() method. For example:
objForm.Date.setToday();
The syntax we've used in this example for creating new prototypes is the
compatible with JavaScript v1.1. There is for those of you more familiar with
JavaScript, you'll know there's a shortcut version which looks like:
Field.prototype.setToday = function (){
dToday = new Date();
var today = (dToday.getMonth() + 1) + "/";
today += dToday.getDate() + "/" + dToday.getYear();
this.setValue(today);
}
However, this method only works in JavaScript v1.2 and higher. Methods created
this way will cause JavaScript errors in Netscape v3.0. If compatibility with
v3.0 browsers is not a requirement you need to stick to, then using this
syntax to create new methods will not cause any problems.
[< Back]
[Index]
[Next >]

|