5 Replies Latest reply: Mar 4, 2013 8:44 AM by jfosteroracle RSS

    Dynamic action for 2 fields in Tabular Form

    jfosteroracle
      Greetings!

      I have a requirement where I need to disable/enable one field in a tabular form for a specific record based on the value of another field in the tabular form for that record.

      For the sake of discussion, in my specific situation - if FISHCOUNT > 1, then LENGTH should be disabled. If count <= 1, then LENGTH should be enabled. It should only disable the records where FISHCOUNT > 1.

      I would like to do this with a dynamic action and I have learned through this forum (thank you very much!) that I can use jQuery for the Event (When) section of the dynamic action.

      So that part would look like:

      Event: Change
      Selection Type: jQuery Selector
      jQuery Selector: td[headers='FISHCOUNT'] select
      Condition: greater than
      Value: 1

      SO far so good. But where I get stuck is how to reference the LENGTH field from the tabular form in the TRUE and FALSE actions, so that when the Event change happens (FISHCOUNT), LENGTH is disabled if FISHCOUNT > 1, or LENGTH is enabled if FISHCOUNT <= 1.

      So referencing the SPECIES field from my tabular form in the True and False actions is where I need help.

      Thanks in advance!

      I am using APEX 4.1.1
        • 1. Re: Dynamic action for 2 fields in Tabular Form
          TobiP
          Hi jfoster,

          maybe this is a bit too much just to be handled by DA alone. First I would not bind to true/false action but let jQuery decide according to the item value. So, there will be some coding.

          You may also want to consider that the disabling also already takes place on page load. So you'll have to bind on two events, and for better maintainability I would put the functionality in a javascript function.

          So the 1. DA would look like that:

          Event: Change
          Selection Type: jQuery Selector
          jQuery Selector: td[headers='FISHCOUNT'] select
          --- so far as you have it, but then
          Action: javascript code
          disableField($(this.triggeringElement));
          The 2nd DA:

          Event: Page Load
          Action: javascript code
          // iterate through all elements of concern
          $.each($('td[headers="SEL"]>SELECT'), function(){
            disableField($(this));
          });
          The function (in Page>Java Script>Function and Global Variable Declaration) could look like that:
          function disableField($sel){
              var $inp = $sel.parents('tr').first().find('td[headers="SPENAMEF"]>input[type="text"]');
              if ($sel.val() > 1){
                  $inp.attr('disabled','disabled');
              } else {
                  $inp.removeAttr('disabled');
              }
          }
          Hope this helps.
          • 2. Re: Dynamic action for 2 fields in Tabular Form
            Tom Petrus
            Keep your setup, and use "execute javascript code" for the true and false action, using this code:

            true action (which would fire when FISHCOUNT changes and the value > 1)
            This is under the assumption that the LENGTH column is an INPUT type and not a select list or the like.
            $(this.triggeringElement).closest('tr').find('td[headers="LENGTH"] input:visible').prop("disabled",true);
            The false code would then be
            $(this.triggeringElement).closest('tr').find('td[headers="LENGTH"] input:visible').prop("disabled",false);
            Don't forget that actually DISABLING an item will prevent it from being submitted to session state. This means that when you would submit your tabular form with disabled elements, which were not disabled at time of retrieval, will produce checksum errors! So it might be a better advice to use the readonly attribute, and maybe spruce up readonly fields through some css. Or use a beforeSubmit action to re-enable disabled fields, so that their values are submitted to session state.
            • 3. Re: Dynamic action for 2 fields in Tabular Form
              jfosteroracle
              Tom, this is very helpful. Can you give me a little more information on how I would use a before-submit action to re-enable disabled fields right before the data is submited? I think that approach would fit my scenario very well.

              Thanks!
              John
              • 4. Re: Dynamic action for 2 fields in Tabular Form
                Tom Petrus
                John,

                You can do this by creating another dynamic action with event "Before Page Submit" (under "Framework Events").
                With a true action which executes javascript, page load unchecked.
                $("input:visible:disabled").prop("disabled",false);
                This will select all visible disabled input items on the page and remove the disabled property.
                • 5. Re: Dynamic action for 2 fields in Tabular Form
                  jfosteroracle
                  I tried out Tom's suggestions for the dymamic action and for clearing the disable before page submit. It works like a charm!! This is exactly what I needed.

                  Can't thank you enough. This forum never ceases to amaze me. Thanks for the help!

                  John