Multiple Forms in Domino Web Applications
I’m having some fun in a legacy application at work. The Lotus Notes/Domino forms I am creating and maintaining are embedded into an ActiveX frame (like a portal).
Prior to this application, I think all of my development has been under the assumption that my HTML form was the only form. Hence, document.forms[0] was my standard. Well, now that I’m working in this embedded application, that isn’t always true. I’ve had to rewrite some of my javascript to work with the current form.
Here’s a few of my current nuggets.
The first thing I had to create was a function to get the current form.
function getMyForm(field) {
// returns form element
if (typeof(field) == "string") {
for (var i = 0; i < document.forms.length;i++) {
if (document.forms[i][field] != null) {
return document.forms[i];
}
}
} else {
var element = field;
while (element != null) {
element = element.parentElement;
if (element.tagName == "FORM") {
return element;
break;
}
}
}
}
I am still debating how to implement the next function. I wasn’t sure if I should pass the form into the function, expect that I already have it (bad design), or get it using the function above. I actually do a mixture of the last two options. I typicall set a global form variable in the JSHeader but check for it in case it is not there.
function getFieldValues(field) {
// Returns array of values. Depends on getMyForm.
var value = new Array;
if (form == null || form.tagName != "FORM") {
var form = getMyForm(field);
}
if (typeof(field) == "string") {
var theField = form[field];
} else {
var theField = form[field.name];
}
if (theField.length == null && theField.options == null) {
value = [theField.value];
} else if (theField.options != null) {
for (var i = 0; i < theField.options.length;i++) {
if (theField.options[i].selected == true) {
value.push(theField.options[i].text);
}
}
} else if (theField.length >= 0) {
for (var i = 0; i < theField.length;i++) {
if (theField[i].checked == true) {
value.push(theField[i].value);
}
}
} else {
value = [''];
}
return value;
}
This is nothing new for a lot of developers and frameworks like jQuery and Prototype handle a lot of this. But in many instances, you’re stuck in legacy code that doesn’t allow you to throw in frameworks (or you really don’t want to have to explain what you’re doing to the other developers).

One Response to “Multiple Forms in Domino Web Applications”
1 housered 18 August 2008 @ 11:04 pm
australia me ibm tom you joke look green bag
Comments: