Tabular form validation

Help
DanielB
2007-08-31
2013-04-22
  • DanielB

    DanielB - 2007-08-31

    Hi Patrick,
    As you can read from my other posts I got the tabular validatation up and running now it works great...there are only one issue.

    In my tabluar form I always show an extra 4 empty rows using an union-all-sql-statement. If I only fill 1 row
    and hit submit the validation fires for the 3 empty rows. Is there any way to handle that?

    I would like to check if my row is completly empty, then don't validate. The problem is I don't know where to start.

    Can you point me in any direction where I can put this if-statement?

    Regards Daniel

     
    • DanielB

      DanielB - 2007-08-31

      To clarify, this is the functionality I want:

      When the user pushes the submit-button only validate the rows where thera are values, if a row is completly empty, do not validate it. Is this possible?

       
      • Patrick Wolf

        Patrick Wolf - 2007-08-31

        Hi Daniel,

        normally it should just validate rows where data is included. Maybe it has something to do with your UNION which isn't considered as "empty". Can you put a testcase on apex.oracle.com of your page so that I can have a look?

        Thanks
        Patrick

         
    • DanielB

      DanielB - 2007-09-01

      Thank you for your reply, Patrick.

      I have just requested a workspace on apex.oracle.com and I will create a testcase there ASAP. Will get back
      when it's done.

      /Daniel

       
    • DanielB

      DanielB - 2007-09-03

      Hm, I did some thinking during the weekend and tested some stuff now on the morning and you are correct, it's the union that causes the error.

      The select:
      select
      "TRANS_ID",
      "INTERNAL_USER_ID",
      "MONTH",
      "REGION",
      "PROJECT",
      "ACTIVITY",
      "TIME",
      "TIME_COMMENT",
      "CREATED_BY",
      "DATE_CREATED",
      "UPDATED_BY",
      "LAST_UPDATED"
      from "#OWNER#"."TIME_TRANS"
      where month = :P50_HEADER_MONTH
      UNION ALL
      SELECT
      null
      ,to_number(sys_context('APEX_TIMEREP','internal_user_id'))
      ,to_number(:P50_HEADER_MONTH)
      ,null
      ,null
      ,null
      ,null
      ,null
      ,null
      ,null
      ,null
      ,null
      from dual
      CONNECT BY LEVEL <= 4

      The problem is caused by to_number(sys_context('APEX_TIMEREP','internal_user_id')) and to_number(:P50_HEADER_MONTH). If I put null there instead and fill out the values in the tabular form it works as expected.

      My problem is now how to populate the values when I save a new row. I can populate the internal_user_id by a trigger but not the month though it's dependent of the value on the screen. I would like to do a process that sets this value before it's sent to the database and saves. Do you know if that is possible?

      I know it's completly non relevant to the Apexlib but if you have any thoughts it will be appreciated...thanks.

      Regards Daniel

       
    • DanielB

      DanielB - 2007-09-03

      I'm going with this solution, hopefully it will work:

      - Page Process
      - On Submit - Before Computations and validations

      BEGIN 
        FOR i IN 1..HTMLDB_APPLICATION.G_F02.COUNT LOOP
          -- G_F05 = region, G_F06 = project , G_F08 = time
          IF HTMLDB_APPLICATION.G_F05(i) IS NOT NULL AND HTMLDB_APPLICATION.G_F06(i) IS NOT NULL AND HTMLDB_APPLICATION.G_F08(i) IS NOT NULL THEN

            -- internal_user_id
            IF HTMLDB_APPLICATION.G_F03(i) IS NULL THEN
              HTMLDB_APPLICATION.G_F03(i) := to_number(sys_context('APEX_TIMEREP','internal_user_id'));
            END IF;

            -- month
            IF HTMLDB_APPLICATION.G_F04(i) IS NULL THEN
              HTMLDB_APPLICATION.G_F04(i) := to_number(:P50_HEADER_MONTH);
            END IF;
          END IF;
        END LOOP;
      END;

       
      • Patrick Wolf

        Patrick Wolf - 2007-09-03

        Hi,

        you can use the APIs of ApexLib here too. It will make the code more readable.

        eg:

        BEGIN
            FOR ii IN 1 .. ApexLib_TabForm.getRowCount
            LOOP
               IF ApexLib_TabForm.hasRowChanged(ii)
               THEN
                   IF ApexLib_TabForm.NV('INTERNAL_USER_ID') IS NULL
                   THEN
                       ApexLib_TabForm.setValue
                         ( pColumnName => 'INTERNAL_USER_ID'
                         , pRow        => ii
                         , pValue      => TO_NUMBER(SYS_CONTEXT('APEX_TIMEREP','internal_user_id'));
                         );
                   END IF;
                   --
                   IF ApexLib_TabForm.NV('MONTH') IS NULL
                   THEN
                       ApexLib_TabForm.setValue
                         ( pColumnName => 'MONTH'
                         , pRow        => ii
                         , pValue      => TO_NUMBER(:P50_HEADER_MONTH);
                         );
                   END IF;
               END IF;
            END LOOP;
        END;

        The advantage is that the code is still understandable in a month. You can use the column names instead the non-saying g_fxx arrays.

        Patrick

         
    • Patrick Wolf

      Patrick Wolf - 2007-09-03

      Grrr. Lost all the formating :-(

       
    • DanielB

      DanielB - 2007-09-04

      Thank you for your reply. I will continue to work with Apexlib!

       

Log in to post a comment.