Sunday, March 27, 2011

Character Counter in Siebel

One of the admirable features of Siebel is its GUI, which allows us to accomodate all the frills and fancies of user. Recently i was asked by one of my colleague to implement i-want-this type of functionality which involved character counter for TextArea field, which should display count of remaining characters which could be filled, in standard siebel eService application. After hours of hit and trial, i came up with one dirty solution.

Lets consider we need to have character counter in place for Description(Maximum 250 characters) in form applet. A basic solution is to have a control below the Description which will display the count of characters left. The document Id for Description is 's_1_1_11_1' and Counter is 's_1_2_45_1'. We can obtain the document ids by richt click on the page. Now comes the key part where we need to add logic to count the characters in Description and populate the counter. This could be accomplished by HTML Attributes property of Description control with below code:

onKeyDown="function fn(){ document.getElementById('s_1_2_45_1').value = 250 - document.getElementById('s_1_1_11_1').value.length; }setTimeout(fn,100);"

The main thing here is on every keydown we are calling a function which will set/reset the counter. Get the length of Description and populating the counter with 250 - length. The issue with this approach is that counter can't be read only. If we make Counter field read only we will not be able to access it in function. Request all siebel champions here to use their fire fighting skills and suggest any other solution.

Happy Counting!!

No comments: