How to Enhance Text Box Prompts in IBM Cognos 8 with On-The-Fly Validation
In this example we’ll show you how to validate user entry of 3 digit numeric codes with a 5 code maximum.
You can change the code according to your own requirements.
This method will display error messages to the user when their entries do not conform to these rules.
Here is how:
1) Create a new IBM Cognos 8 Report Studio report.2) Add a prompt page to your report.
3) From the Toolbox menu, drag a Text Box Prompt object onto your prompt page. The “Prompt Wizard” opens. Leave the default parameter name and click Finish.
4) Select the prompt object and assign it a name by navigating to the Properties area (bottom left of the page) and entering a value in the Name property, which can be found in the Miscellaneous section at the bottom of the list (this example uses a prompt object named “sPrompt” and this will be referenced in the JavaScript).
5) And now the fun part! Drag an HTML Item object directly to the right of the prompt. Assign its’ Description property the following value: prompt modifier.
TIP: Adding descriptions to your HTML Items makes it easier to identify them later when more than one is present in the report.
6) Now enter the following code into this HTML Item by either double-clicking it or select the HTML property:
<script> fW._textEditBoxsPrompt.onblur=validatePrompt; </script> |
7) Now, we will add a second HTML Item to top of the page to hold our functions. Once the HTML Item is added to the report, describe the item by going to the Description property and typing in “functions”. Your prompt page should now look like the image below:
8 ) The following code will allow users to enter a maximum of five (5) numeric codes separated by commas. Any other characters that are encountered will throw an error. The section for a proper validation was purposely left blank to allow readers to enter their own success message or routine.
<script>
var fW=(typeof getFormWarpRequest == “function” ?
getFormWarpRequest() :document.forms["formWarpRequest"]);function validatePrompt()
{
str=fW._textEditBoxsPrompt.value; if (!(str==null||str==”"))
{
str=str.toUpperCase();
str= str.replace(/ /g, “”); // remove all spaces
str= str.replace(/,+/g, “,”); // replace multiple commas by one
str= str.replace(/,$/g, “”); // remove trailing comma
str= str.replace(/^,/g, “”); // remove leading comma
var patvalidchar = new RegExp(“^[0-9,]+$”);
var pat3char=new RegExp(“^([0-9]{1,3},)*$”); // 3 digit code
var pat5char=new RegExp(“^([0-9]{1,3},){0,5}$”); //more then 5 codes
// characters other than numbers were used…
if (patvalidchar.test(str)==false)
alert(“Codes may be comprised of only numbers.”);
// codes are more than 3 digits long and only numeric …
else
{
if (pat3char.test(str + “,”)==false)
alert(“Codes must be at least three digits.”);
// more than 5 codes were entered …
else
{
if (pat5char.test(str + “,”)==false)
alert(“Please enter no more than 5 codes”);
// Enter code here for successful validation …
else
{
return true;
}
}
}
}
// Enter code here if Text Box is Empty …
else
{
alert(“No values entered.”);
}
}
</script>
------------------
Source: Irongroupside.com
September 16, 2009 by
No comments:
Post a Comment