9 Replies Latest reply: Apr 2, 2013 4:08 AM by 908320 RSS

    how to set value in one column in Tabular form depending on other column?

    drama9346
      Hi every one!

      I use Apex 4.1.
      My question is how can I set value of column in tabular form depending on other column?
      I have tabular form and when I insert value in column Content, I want that value in column Note get changed with note, which is generated with pl/sql function (function return string if typed value is in range).

      I tried to use javascript like
       $('input[name=f02]').live('change', function(){
      if($(this).val()!='1'){
      $('input[name=f03]').val("test")}
      }); 
      for setting value of column note to test if typed value in column content isn't 1, but this code set value to all rows and I need to set only specifed row.

      Can someone give me a some hint how to achieve this if it is possible?

      Regards,
      drama9346
        • 1. Re: how to set value in one column in Tabular form depending on other column?
          Tom Petrus
          $('input[name="f02"]')
          This will select all input elements with name attribute set to "f02". Of course, executing it with name="f03" will select all input elements with the name attribute set to "f03". Does not change when you call it within a loop or change event.

          To select an input element with name="f03" on the same row as the changed element, you can traverse accordingly from the triggering element:
          $('input[name=f02]').live('change', function(){
             if($(this).val()!='1'){
                $(this).closest("tr").find('input[name=f03]').val("test")
             }
          });
          $(this).closest("tr")
          This will get the closest tr element traversing up from "this"
          .find('input[name=f03]')
          This will then find an input element with name="f03" in the element returned by .closest("tr"), ie in the same row.
          • 2. Re: how to set value in one column in Tabular form depending on other column?
            drama9346
            Hi Tom!

            I noticed that it not change Note value if I put into content 1. For now I solve that problem with adding one more if statement and then I clear value of column note. Is there some other solution for this?

            Could you advise me also how can I call pl/sql function for verifying if inserted value is in range and then write returned string into column note?

            Regards,
            drama9346
            • 3. Re: how to set value in one column in Tabular form depending on other column?
              Tom Petrus
              It depends on what you want the "if" statement to do on the triggering element's value. Do you simply want to check if there is a value present or not? If so, then altering your if to
              $(this).val()!=''
              would do that, and writing a '1' in it would still trigger.

              As for communicating with the database: define either an application process or a process on the page with process point on-demand. This is ajax, and you may want to read a bit on it!
              Replace XXXXXXXX with the name you gave your process.
              $('input[name=f02]').live('change', function(){
                 //if value of changed field differs from an empty string
                 if($(this).val()!=''){      
                    //put target element in a var to reference it in the ajax success callback
                    var that = $(this).closest("tr").find('input[name=f03]');
                    
                    //this will fire an asynchronous call to the server
                    //wwv_flow.show: request to the current page
                    //p_request: application process name
                    //p_flow_id: application id
                    //p_flow_step_id: page id on which the process is located. Set to 0 if the process you 
                    //                want to call is not defined on the page but is in the shared components
                    //p_instance: session id
                    //x01: a temporary variable. You can reference this in your process by using apex_application.g_x01
                    $.post('wwv_flow.show', 
                           {"p_request"      : "APPLICATION_PROCESS=bogus",
                            "p_flow_id"      : $v('pFlowId'),
                            "p_flow_step_id" : $v('pFlowStepId'),
                            "p_instance"     : $v('pInstance'),
                            "x01"            : $(this).val()
                            },
                            function(data){
                               //data is the return
                               //maybe you want to perform some checks on that?
                               if(data){
                                  $(that).val(data);
                               };
                            }
                            );
                 };
              });
              • 4. Re: how to set value in one column in Tabular form depending on other column?
                drama9346
                Hi!

                Tom please confirm if I understand you (or correct me). I need to create on demand process (do I choose process for tabular form or regular process for page?) and then I need to put code you wrote on my page as I put code from previous post (of course I must write correct process name in p_request parameter)

                Regards,
                drama9346
                • 5. Re: how to set value in one column in Tabular form depending on other column?
                  Tom Petrus
                  You will need to create a process on your page of type PLSQL, and put this process at the "on demand" point of the page. In this process you can execute the PLSQL you need. ie to retrieve the note value as described in your OP:
                  and when I insert value in column Content, I want that value in column Note get changed with note, which is generated with pl/sql function (function return string if typed value is in range).
                  In this process you will need to provide a value back to the call, and you can do that by using htp.p. Example:
                  DECLARE
                     --putting x01 in a var to simplify
                     l_test_var VARCHAR2(200) := apex_application.g_x01;
                     l_return VARCHAR2(200);
                  BEGIN
                     -- a simplistic test
                     IF LENGTH(l_test_var) BETWEEN 10 AND 20 THEN
                        l_return := 'String is between 10 and 20';
                     END IF;
                  
                     --this will write l_return to the buffer, and the ajax callback will receive this
                     htp.p(l_return);
                  END;
                  And the code i wrote above, which is javascript, would need to go where your current code is which binds to the onchange event. The result should be that when a change is made to that element, an ajax request is made to the server. When this call completes it will put the returned value into the desired element.
                  • 6. Re: how to set value in one column in Tabular form depending on other column?
                    drama9346
                    Hi!

                    Tom I set up application with tabular form like mine on apex.oracle.com, because thing doesnt work.

                    Could you please look into and help me with that?

                    workspace: drama9346
                    user: test
                    pass: test

                    Regards,
                    drama9346
                    • 7. Re: how to set value in one column in Tabular form depending on other column?
                      Tom Petrus
                      Ah, the age old problem. That is what you get for using array names! Your "Content" column is actually array "f03", and the "Note" column is array "f04". "f02" was the "Id Element" column, which can't be changed since it is readonly. I switched these around in the javascript function, and now it works.
                      • 8. Re: how to set value in one column in Tabular form depending on other column?
                        drama9346
                        Oh yes. I changed ID_ELEMENT column because I try to create tabular form process for comparing values.

                        Thank you for your help!

                        Regards,
                        drama9346
                        • 9. Re: how to set value in one column in Tabular form depending on other column?
                          908320
                          Hi,

                          hope you will get the solution from the below example in the document :


                          (link removed by moderator)

                          Thanks.

                          Edited by: BluShadow on 02-Apr-2013 12:08
                          linking to promote your own blog is a breach of the Terms of Use of the forums