12 Replies Latest reply: Jan 23, 2013 4:36 AM by 911327 RSS

    Apex 4 Date Field Validation

    485032
      Apex 4 on 10.2.0.3 Database:

      I have a form which has a Date field(Received_date), User can enter and modify the field there, I want to put a validation on the field so when user first time choose the date, it should be either today or later, not earlier than today's. But I want the validation only works on first time entered value, not on the ones already have that field filled(when modify existing records and that field already have a date filled in)

      I tried Item Attri(Min set to +0d) and also tried to create an item level validation like this (Function returing error text)

      if :P3_RECEIVE_DATE<sysdate then
      return 'Not A Valid Date';
      else
      return null;
      end if;

      That solved the first time validation. But problem is that it didn't work for existing records who already have the date there, For example, when I open an existing record which already have a date there(earlier than today's date), when try to save it, it also trigger the validation, which I don't want.

      I know I can create a trigger in database side but is there any way to achive this on the Apex side?

      Thanks
        • 1. Re: Apex 4 Date Field Validation
          le
          Hi,

          On your form you have an item that keeps primary key value.
          When you are inserting new record this value is null.

          Make your validation conditional - run it only if primary key item is null

          Regards,
          Lev
          • 2. Re: Apex 4 Date Field Validation
            485032
            Thanks Lev,

            Here is what I want:

            The field is not mandatory so it's possible user leave it empty when they first create the record(with other fields entered), then later on when they open the form and edit the record, he can enter the Date field and when he does, I want the validation process also triggered.

            1. If user create a total new record, if he put a date into the field, it must be today or later; he can leave that field blank at this time though
            2. Later When Edit, if the the field is still empty on that record, when user put date there, it must be today or later; If the field is not empty(may contain date earlier than today) and user want to modify it, it must be today or later; but if he doesn't want to modify that field, the value there is ok

            So whenever user enter a date or modify a date, I want the new date put there is either today or later.
            • 3. Re: Apex 4 Date Field Validation
              le
              I'm talking about primary key - it's mandatory!

              It could be hidden and probably generated by sequence or trigger but
              there should be such field in the form.

              Put example on apex.oracle.com - it will be easier to help you

              Lev
              • 4. Re: Apex 4 Date Field Validation
                485032
                Thanks Lev,

                Here is the example: http://apex.oracle.com/pls/apex/f?p=48914

                See the receive date col, what I want is that if I create a new record and put the date there, the date can only be today or later--- This can be care of by the Primary Key+Validation you mentioned;

                But that doesn't work When I try to Edit the second record, it's receive_date is empty now and when I edit and put a date there, I want the date also to be either today or later.

                Thanks

                Mike
                • 5. Re: Apex 4 Date Field Validation
                  le
                  Hi Mike,

                  I also need access to your workspace (workspace, user name, password)


                  Lev
                  • 6. Re: Apex 4 Date Field Validation
                    485032
                    Hi Lev,


                    Thanks

                    Mike

                    Edited by: mike on Aug 19, 2011 11:23 AM
                    • 7. Re: Apex 4 Date Field Validation
                      le
                      Mike,

                      In your situation it's even easier - you have page 2 that is used for insert and page 3 that is used for update.
                      Date is validated only on page 2 (when inserted)

                      But you should also consider your business logic - what if user inserts correct (future) date and immediately after that updates record and enters wrong date.


                      Lev
                      • 8. Re: Apex 4 Date Field Validation
                        485032
                        Thanks Lev,

                        The validation need to be performed on both insert page(2) and edit page(3); on Edit page, if the existing record(record 2) is having null in the reveive_date, he can put a date there but the date need to be today or later.

                        I will have another logic in place: if the received_date is not empty, they are not allowed to modify it anymore. So the validate need to take place first time user put a date there, but he can leave it empty when he first create the record.

                        Thanks

                        Mike
                        • 9. Re: Apex 4 Date Field Validation
                          le
                          Mike,

                          Look at the page 3.

                          1. added :P3_RECEIVE_DATE_BEFORE - hidden
                          2. Computation "before regions" P3_RECEIVE_DATE_BEFORE
                           begin
                            return :P3_RECEIVE_DATE;
                           end;
                          It saves initial value of P3_RECEIVE_DATE
                          3. Validation P3_RECEIVE_DATE
                           begin
                           if TO_DATE(:P3_RECEIVE_DATE,'dd-MON-YYYY') < sysdate then
                            return false;
                           else
                            return true;
                           end if;
                          end;
                          This validation is conditional - it's executed only if P3_RECEIVE_DATE_BEFORE is not null

                          Hope it helps.

                          Lev
                          • 10. Re: Apex 4 Date Field Validation
                            485032
                            Thanks A LOT!

                            It works, just the way I want it to be.

                            Have a great weekend!

                            Mike
                            • 11. Re: Apex 4.2 Date Field Validation
                              user10694353
                              Hello,
                              i've to validate if my :P58_TITDATEECHEANCE higher than :P58_DATEJOUISS in apex 4.2
                              I've code a Function returning booelan like this. But when i test it and change the dates i always have the same result (my message error)
                              Anyone have an idea?

                              IF TO_DATE(:P58_TITDATEECHEANCE,'DD-MM-YYYY') >= TO_DATE(:P58_DATEJOUISS,'DD-MM-YYYY') THEN
                              return true;
                              ELSE
                              return false;
                              END IF;
                              • 12. Re: Apex 4 Date Field Validation
                                911327
                                HI
                                i wont to validate an item (p7_id) and i wont that if somebody try to delete the item building to show a message that explain that you have to delete first the houses that belong to this building... haw can i do that?