Author Topic: Value prompt  (Read 2880 times)

Offline Sunchaser

  • Community Leader
  • *****
  • Posts: 155
  • Forum Citizenship: +2/-0
Re: Value prompt
« Reply #15 on: 05 Apr 2008 08:00:03 am »
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:
Code: [Select]
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
Code: [Select]
<script text=javascript>
var Lbox = document.forms["formWarpRequest"].elements["_oLstChoiceslstJS"];
Lbox.attachEvent("onclick", m_click);
</script>

HTML Item2
Code: [Select]
<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.

Offline baskarbis@gmail.com

  • Associate
  • **
  • Posts: 3
  • Forum Citizenship: +0/-0
Re: Value prompt
« Reply #16 on: 31 Jan 2012 06:01:12 am »
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



Offline kss001

  • Full Member
  • ***
  • Posts: 37
  • Forum Citizenship: +2/-0
Re: Value prompt
« Reply #17 on: 12 Apr 2012 04:03:26 am »
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.