This discussion is archived
10 Replies Latest reply: Apr 16, 2012 12:18 PM by Bob Sacamano RSS

How to disable/enable select list in a tabular form ?

417717 Newbie
Currently Being Moderated
APEX 4.0+
I have two select lists, A and B in a tabular form. I want to disable/enable select list B when I choose a value from select list A.
What is the code for this? Can I do it in a Dynamic Action?
thanks in Advance
PaulP
  • 1. Re: How to disable/enable select list in a tabular form ?
    skahlert Newbie
    Currently Being Moderated
    Hello Paul!

    Carry out the following steps:

    1. Create a dynamic Action using advanced mode.

    => Name "DISABLE_SELECTLIST" => Event "CHANGE" => SELECTION TYPE "ITEM(s)" => Item(s) => "YOUR ITEM"

    2. Action "DISABLE" => Selection Type "YOUR LIST TO BE DISABLED"

    3. Save the Dynamic Action and edit by having a look at the TRUE ACTIONS => uncheck the "Fire on Page Load" option.

    Hope it helps!

    Best regards,

    Sebastian
  • 2. Re: How to disable/enable select list in a tabular form ?
    417717 Newbie
    Currently Being Moderated
    Sebastian,
    Unfortunately I have a tabular form whose source is an sql query updateable report not a form with individual items. You therefore cannot select an Item name as you suggested in step 1,
    thanks anyway for responding.
    PaulP
  • 3. Re: How to disable/enable select list in a tabular form ?
    417717 Newbie
    Currently Being Moderated
    Sebastian,
    Unfortunately I have a tabular form whose source is an sql query updateable report not a form with individual items. You therefore cannot select an Item name as you suggested in step 1,
    thanks anyway for responding.
    PaulP
  • 4. Re: How to disable/enable select list in a tabular form ?
    skahlert Newbie
    Currently Being Moderated
    Hello Paul!

    No problem! I didn't know that!

    Then go to the REPORT ATTRIBUTES and edit the respective report columns that contain your select lists.
    For each column you need to add a Class attribute in ELEMENT ATTRIBUTES e.g.:
    class="list1"
    and
    class="list2"
    Now create the Dynamic Actions as decribed but don't select "ITEM(s)" as SELECTION TYPE but "jQuery Selector" and type in
    .list1
    for the triggering element.

    The affected element will be of type jQuery Selector as well (.list2).

    This should work for you!
  • 5. Re: How to disable/enable select list in a tabular form ?
    417717 Newbie
    Currently Being Moderated
    Thanks for your quick reply.

    Question, will I have the same issue using your method that I encountered and wrote about here? I used a different method than the one you suggested here.

    How to save a tabular form when a column/field is disabled programatically?

    regards
    Paul P
  • 6. Re: How to disable/enable select list in a tabular form ?
    Bob Sacamano Newbie
    Currently Being Moderated
    Hi - I followed the steps (Create a dynamic Action) outlined in this post and this works for me except for one problem. It disables the LOV in every row. I only want to disable those rows that have the defined disable LOV values picked. How do I do that?

    Edited by: Bob Sacamano on Apr 13, 2012 1:16 PM
  • 7. Re: How to disable/enable select list in a tabular form ?
    417717 Newbie
    Currently Being Moderated
    Hi Bob,
    I ended up doing it a different way. I got this solution off the forum but can't remember where, so I need to give credit to another developer. I've just adapted it a bit;
    1) FIrst find out the "f" array id's for each LOV column (at runtime view source and search for the column names) Mine were f07 and f08
    2) Put the following code in the page attribute "HTML Header and Body Attribute"
     <script type="text/javascript">
    function disableColour(checkcolumn,disablecolumn)
    {
     var f1 = document.getElementsByName(checkcolumn);
     var f2 = document.getElementsByName(disablecolumn); 
     var k; 
     if (f1) 
     {
      for (k = 0; k < f1.length; k++)  
      {   
        if (f1[k].value != 'SPECIMEN' && f1[k].value != 'SUBSPECIMEN')   //<===this is where you put all the options that will disable the other LOV using and (&&), or (||)
        {
         f2[k].disabled= true;    
         f2[k].style.backgroundColor = 'silver';   
         } 
        else
        {
         f2[k].disabled= false;    
         f2[k].style.backgroundColor = 'white';   
        } 
       } 
     }
    }
    function enableColour(column)
    { 
      var x = document.getElementsByName(column); 
      var k;
      if (x) 
      {  
        for (k = 0; k < x.length; k++)  
        {   
          x[k].disabled= false;
          x[k].style.backgroundColor = 'white';  
         }
       }
    }
    </script>
    2) In the page attribute "Page HTML Body Attribute" put

    onload="disableColour('f07','f08');"

    3) In the updateable report definition under "Report" on the column attribute of the LOV column (the one that drives the enabling/disabling of the other LOV) in "Element Attributes" put

    onchange="disableColour('f07', 'f08');"

    4) Now to avoid the horror MRU update error common to tabular forms, you have to temporarily re-enable all LOV fields prior to running the "Apply MRU" update process(disabled fields get set to the null LOV value defined against the LOV),
    so on the Save (Apply changes) button enter

    Attributes:
    Action ==> Redirect to URL
    URL Target==> javascript:enableColour('f08');doSubmit('SUBMIT');

    It should all work now.

    Hope this helps
    PaulP
  • 8. Re: How to disable/enable select list in a tabular form ?
    Bob Sacamano Newbie
    Currently Being Moderated
    Thanks PaulP, but it didn't work for me. Also, when I followed step 2, it wouldn't accept it. I got this error: *"You may not declaratively set cursor focus if you specify an ONLOAD in this attribute. You can programatically set cursor focus by using the following syntax: onload="mystuff(); first_field();""* Even so, I couldn't get the function to disable the LOV anyway. It ignored function.

    Here's what I did. My LOV is f02. What I want to do is disable this LOV (f02) with some of its LOV values ('Approved' or 'Remove').


    Here's how I modified the function:

    <pre class="jive-pre"><script type="text/javascript">
    function disableColour(checkcolumn,disablecolumn)
    {
    var f2 = document.getElementsByName(checkcolumn);
    var f2 = document.getElementsByName(disablecolumn);
    var k;
    if (f2)
    {
    for (k = 0; k < f2.length; k++)
    {  
    if (f2[k].value != 'Approve' && f2[k].value != 'Remove') //<===this is where you put all the options that will disable the other LOV using and (&&), or (||)
    {
    f2[k].disabled= true;
    f2[k].style.backgroundColor = 'silver';
    }
    else
    {
    f2[k].disabled= false;
    f2[k].style.backgroundColor = 'white';
    }
    }
    }
    }
    function enableColour(column)
    {
    var x = document.getElementsByName(column);
    var k;
    if (x)

    for (k = 0; k < x.length; k++)
    {  
    x[k].disabled= false;
    x[k].style.backgroundColor = 'white';
    }
    }
    }
    </script></pre>



    Do you see any problems?
  • 9. Re: How to disable/enable select list in a tabular form ?
    417717 Newbie
    Currently Being Moderated
    OK Bob,
    First things first.
    In your page attributes make sure that the attribute "Cursor Focus" under "Display Attributes" is set to "Do not focus cursor". Then try it again. The LOV should look disabled for the appropriate values.
    Also get rid of the comment in the javascript.i.e. //<===this is where you put ...etc That was just to show you where to put your conditions for disabling the LOV.
    Just a query,
    If you disable your LOV wrt values in the same LOV (f02) then how are you going to re-enable that LOV field again? Normally the way it works is that an LOV drives the enabling/disabling of a second LOV or text item.
    PaulP
  • 10. Re: How to disable/enable select list in a tabular form ?
    Bob Sacamano Newbie
    Currently Being Moderated
    Hi PaulP - I set everything up as you indicated, but it still doesn't disable the LOV. I double checked everything. Unfortunately you can't post screen shots here to show.

    To answer your other question, once the end user saves the LOV as 'Approve' or 'Remove', I don't want them to be able to re-enable it. That's desired functionality. In the meantime, I'm going to have to go in another direction with this so I can meet my deadline. I appreciate your help.

    Thanks again.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points