If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Value prompt

Started by aamuktha, 25 Mar 2008 04:27:35 AM

Previous topic - Next topic

aamuktha

hi Friends,

i have value prompt on prompt page with following properties:

Select UI : List Box
Multi-Select : Yes
the value prompt contains static choices.

My query is , i need to select only one or two values from value prompt not more than that.( means the user can select upto two values not more than that.)

Please tell me how to solve this issue.

Thanks in advance....

biejorrun

You could create 2 single-select prompts, and combine them with an "OR"-operator.

aamuktha

i think u did get the point what i have asked .

a value prompt contains 10 static choices. i can select at a time one or max two only not more than that.
If i use multi select property as yes i can select at a time one or two or three or all values . but in this case i should not select more than two.

i think this explanation may have given you still more in detial.

Thanks....

biejorrun

Well then, you're welcome!

subhash

hi,

u can achieve this by keeping the select ui as check box.after keeping the select ui property as checkbox take a HTML item and write the java code within the loop. u can solve that.....

ok.

aamuktha

Thanks Subhash.

But can't we achive with list box.

if it works with check box , can u help me with java script (if u knew it). i don't know anything about java script.

Sunchaser

Hello


I don't know if you have already solve your problem; If not, I post here a few lines of code, in order to try to help you.
This is not my favorite solution, but I don't have enough time to work on javascript to get what I was thinking of. Explanation: the code below creates a other 'Finish Button' to replace the default Finish button on the prompt page, and allow a check on the number of selected Items before running the report.
I would prefer to catch an event, like 'OnClick()' or 'OnChange()' or something like that on the listBox object, and I saw It is surely possible but I've never done this yet.
So, here's the code:

<!--owner-drawned button for prompting-->
<button type="button" name="finishAlert" id="finishAlert"
style="" class="clsPromptButton"
onmouseover="this.className = 'clsPromptButtonOver'"
onmouseout="this.className = 'clsPromptButton'"
onClick="mCheck()">Finish</button>

<!--function called on-click-->
<script text=javascript>
function mCheck()
{
var Lbox = document.forms["formWarpRequest"].elements["_oLstChoiceslstJS"];
var n_count = 0;
for (var i = 0; i < Lbox.length; i++)
{
if (Lbox[i].selected)
{
n_count++;
}
}
if (n_count > 2)
{
alert("Too much!!");
}
else
{
promptButtonFinish();
}
}
</script>

<!--insertion of button-->
<script xmlns:xIE5="http://developer.cognos.com/prompting/x IE5">
var promptButtonfinishCheckDate = new
CPromptButton (document.getElementById("finishAlert"),
PROMPTBUTTON_FINISH, true);
pageNavigationObserverArray pageNavigationObserverArray.concat('promptButtonfinishAlert');
notify();
</script>

. The property 'Name' of the listbox is 'lstJS' (for this example)
. "_oLstChoices" is a 'static value' in order to reach the good object type

Hope it will help,
++
;)

aamuktha

Thanks..

Let me try it out.

Sunchaser

Hi,

As I've done in a subject of sir cognoise007, there is a way for catching some events of listbox.
Here is a short code, that should be put in a HTML Item after the listBox:

<script text=javascript>
var Lbox1 = document.forms["formWarpRequest"].elements["_oLstChoiceslstJS1"];
var attached = Lbox1.attachEvent("onchange", mCheck);
</script>


So, the little function 'mcheck()' described before should be stored in a another HTML Item. You will have to make some more checks because, if 'mcheck()' stay as it was described before, the report will be submitted as soon as a Item is selected in the listBox.

++
;)

aamuktha

hi sunchaser,

It is not working.

Sunchaser

Hi aamuktha,

So, I think you should tell more about what you have done  ;D
And what it is 'saying', what sort of error code ?

First, are you sure of the name of the Value prompt ? -> in the short code I posted, the name of this object is "lstJS1" (the last part of "_oLstChoiceslstJS1") and you should check that you change this point with the real name of your Value prompt (I think it has to be defined inevitably).

I will put this part:

<!--function called on-click-->
<script text=javascript>
function mCheck()
{
var Lbox = document.forms["formWarpRequest"].elements["_oLstChoiceslstJS"];
var n_count = 0;
for (var i = 0; i < Lbox.length; i++)
{
if (Lbox[i].selected)
{
n_count++;
}
}
if (n_count > 2)
{
alert("Too much!!");
}
else
{
promptButtonFinish();
}
}
</script>

in a other HMTL Item, put down at the beginning at the page; the short piece of code I posted at last should be in a separated HTML Item, put down after the Value prompt.

If my memory is good enough, I tried it and it was working (I'm going to check this anyway...)

Sunchaser

Hi aamuktha,

I'm too stupid, in my last asnwers I forgot what you were asking at the beginning, so with the last idea the report will run as soon as an Item is selected in the list.
I apologize.  :-[

But I'm still thinking that the first 'technique' should work, there's no reason...

For the last idea, I'm actually trying to disable one of the 'standard' prompt-button ("Next" or "Finish") as soon as more than 2 Items (for example) are selected in the list, but It seems more difficult that I imagined first.
If anybody knows ...  ;)

++

aamuktha

hi Sunchaser,

I have tried with the fisrt code by changing the list name as u said . but it is not working. still i am unable to select up to two values in value prompt.i am able to select only one value in value prompt.

Regards,
aamuktha

Sunchaser

Hello,

Yes I know aamuktha, it was what I was trying to explain yesterday in my last message: I apologize, It was a mystake. The report will run in fact as soon as you select one Item in the listbox ... I answered too fast.

Instead of that, I was trying just to count the number of selected Items when a user click in the list (by catching the 'OnChange' event as I've done), and then to disable the 'Standard' buttons like 'Finish' or 'Next', in order to stop the user if more than two Items where selected.
But it was more difficult than I believed, and It is not working fine for the moment.

Just remember that the solution I gave on the 28 March (the one with the script for a 'owner-draw' FinishButton) is possible to use.

I will tell you if ever I succeed in what I'm trying now...

++

aamuktha

Thanks a lot for your help.

Sunchaser

Hello,

It is strange for me, but I can't dynamically disable the "PROMPTBUTTON_NEXT" or "PROMPTBUTTON_FINISH", and I mean I still don't know how. Maybe someone has the solution (?)...
I tried to make a short copy of some code found in .JS in Cognos repository, like that for example:

function EnableButton(var_enabled)
{
if (pageNavigationObserverArray)
{

var kCount = pageNavigationObserverArray.length;

for (var j=0; j<kCount; j++)
{
var promptElement = eval(pageNavigationObserverArray[j]);
var promptElementType = promptElement.getType();
if (promptElementType == PROMPTBUTTON_NEXT || promptElementType == PROMPTBUTTON_FINISH)
{
promptElement.setEnabled(var_enabled);
break;
}

}
}
}

In fact, it's working but as soon as there's a change in a promptElement, Cognos is checking the values in these elements and in our case ( as the listBox has a SelectedIndex > -1 ) Cognos considers that the report can run -> so the finishButton is enabled again ! (after the short code above is executed)
I don't know how to manage to put some "Flag", or "By pass" this event.
If anyone else knows, It could be very interesting.

The last solution is catching the "onclick" event on the listBox, and automatically deselect an item as soon as there are more than 2 items selected:
HTML Item1

<script text=javascript>
var Lbox = document.forms["formWarpRequest"].elements["_oLstChoiceslstJS"];
Lbox.attachEvent("onclick", m_click);
</script>


HTML Item2

<script text=javascript>
function m_click()
{
var n_count = 0;
for (var i = 0; i < Lbox.length; i++)
{
if (Lbox[i].selected)
{
n_count++;
}
}
if (n_count > 2)
{
Lbox.options[Lbox.options.selectedIndex].selected = false;
}
}
</script>


So, now, you can't select more than 2 items in the list.

But you will surely see that it is not perfect:
-> if you select the items (multiselect of course) from the last Item in the list to the first (from the bottom to the top of the list), the code will deselect the last clicked Item and that point is OK.
-> if you do this from the first to last item, the code will deselect the previous selected Item.

I don't know why, I've never seen this with C++Builder or Delphi objects, sorry.

baskarbis@gmail.com

Hi aamuktha,

You can achieve to select only one or two values from value prompt not more than that. suppose if user click on select all button that time also  wont allow . that will give alert message and finish button will  disable.

Steps:

please find the attached xml file and user the below information for checking the xml file. 
             Pakcage:GO Sales(Query)
              version: 8.3

Step1: create one table beside the value prompt in that table you can paste below code
Html Item: <span id ="alert_msg">

Text Item: * You can select only up to 2 values. Use CTRL key to unselect one are    more of your selections.

Html Item:</span>

Step2: In value prompt both sides you can drag two html items for identifying the value prompt

value prompt left side html item: <span id='list'>

value prompt right side html item: </span>

Step3:
you can paste this code beside the finish button

<script>
//Create a handle for the alert message
var alert_msg = document.getElementById("alert_msg");

//Create a handle for Finish button by getting a list of elements on the page with "button" tag
var buttons = document.getElementsByTagName("button");

//Get a list of elements on the page with "select" tag
var value_prompt = document.getElementsByTagName("select");
value_prompt[0].onchange = validateSelection;

//Hide alert message when page loads
alert_msg.style.display='none';

function validateSelection()
{
   var selectionCount = 0;
   for (i = 0; i < value_prompt[0].options.length; i++)
   {
      if (value_prompt[0].options.selected)
      {
        selectionCount = selectionCount + 1;
      }
   }
 
   if(selectionCount >2)
   {
     buttons[1].style.display='none';
     alert_msg.style.display='';
   }
   else
   {
     buttons[1].style.display='';
     alert_msg.style.display='none';
   }
}


var checkboxes = document.getElementById('list').getElementsByTagName("A");
checkboxes[0].attachEvent('onclick',uncheckAll);

function uncheckAll()
{
alert("* You can select only up to 2 values. Use CTRL key to unselect one are more of your selections.");

buttons[1].style.display='none';
alert_msg.style.display='';
}

</script>



I hope this will help for you query.


Thanks
bhaskar



crn.siva

Hi,

I am also suffereing with this issue, almost everthing is ok, except select all.

My requirement was limited to 300 values. if the prompt having less than 300 values that time using the above script & using select all option that time also it is giving alert message, this time i don't want.

please can any one help me on this.