Friday, November 12, 2010

Dynamical counter in Lotus Notes client

Have you ever tried to show length of field (f.x. just below the field) ?

Let me show my example, I've a form, there I have couple fields I need to show length of it (because there is some validation of length for this field).

So when user input new char in Title field, Character count should increase to 1. Know how to do that? I believe many of you know, but anywhere I would like to share this approach.

There are actually 2 fields: 1 for input and another one is just below the Title of field (computed type).

What we need to do - use some simple JavaScript lines..

step 1.
go to JS Header even in form/subform and put there couple lines of JS (select Run: Client and JavaScript)

 var f = document.forms[0];  
 var stopDynamicalCounter = 0;  
 function updateCharCounter(delay) {  
   if(stopDynamicalCounter == 0) return;  
   f.AlternateTitle_length.value = f.AlternateTitle.value.length;  
   setTimeout( 'updateCharCounter( ' + delay + ' )', delay);  
 }  

step 2.
select input-field, and go to onFocus event, select Run: Client and JavaScript and put there 2 lines
 stopDynamicalCounter = 1;  
 updateCharCounter(100)  

step 3.
select input-field, and go to onBlur event, select Run: Client and JavaScript and put there 1 line

 stopDynamicalCounter = 0;  

That's all.

4 comments :

Anonymous said...

Hey! Dinosaurs are gone, it's 2010.

:) I am really sorry people who do not use xPage's with a full power.

Any way, this script also useful for me, Thank you!

David Leedy said...

Good post. I've done this once or twice before.. I think Chris Blatnick at interfacematters.com originally posted something similar years ago.

I think I've had some performance issues with this on Citrix in earlier versions... Either that or maybe is was because I was doing some field highlighting at the time. Forget now..

It is nice to be able to pull this off in the Notes client.

Carl Tyler said...

I'm wondering why you have a timer? There is probably a really good reason you have, so I'm interested in learning what it is.

Why not just have something like this in the onkeyup ?

var f = document.forms[0];
f.AlternateTitle_length.value = f.AlternateTitle.value.length;

Carl Tyler said...

Doh, I think I got it, this is Notes client not Web browser.