Tuesday, February 20, 2007

Javascript in Lotus Notes Applications

To get info about a "javascript object", for instance the form, make an action button (client javascrip) with this code:

var f = eval(prompt("State the object (e.g. window, document,forms[0])","document.forms[0]"));
var str="";
for(item in f){ str+=item+" = "+f[item]+"\n"; }
alert(str);

This code puts up a prompt asking for the name of the object.

Example (using document.forms[0]):
Using window:


As far as I can tell, you have access to the form elements as you would on the web. You can also override @Command([FileSave]) with the onSubmit event (client->javascript).

If you have five fields named field1, field2, field3, field4, field5.

You can have validate that all the field has values onsubmit:
var allHaveValues = true;
var f = document.forms[0];

for(var i=1;i<6;i++){
if(f['field'+i].value==""){
allHaveValues = false;
alert("field"+i+" doesn't have a value.");
break;
}
}
return allHaveValues; //false if one off them doesn't have value No formula or lotusscript needed. Now.. Someone tell me how to add events in an unobtrusive /dynamic way in notes-applications, and I'll be a happy young lad. :)

Update: It looks like there is full support javascript objects as well.

You can for instance write:
var Form = {
getValue : function(field){
switch(field.type){
case "text":return field.value;break;
case "radio":return getRadioVal();break;
}
},
setValue:function(field, value){
alert("Not yet implemented! You get the point..");
}
}

0 comments: