Forum Stats

  • 3,827,397 Users
  • 2,260,770 Discussions
  • 7,897,225 Comments

Discussions

Trigger a Display item when the value is changed by entering data to a Text item

2898128
2898128 Member Posts: 10
edited Mar 9, 2015 4:49AM in Forms

this is my form

Untitled 1.png

the SEATS LEFT box is a display item with a fixed to total value of 217. When I enter a value in either of the three boxes which are Adult, Child, and Infant, the SEATS LEFT will subtract the total values of those three text items.

So I want it to stop when it reaches 0 (ZERO)  and gives a message.  I tried putting WHEN-VALIDATE AND POST_CHANGE triggers to the SEATS LEFT with this code, but nothing happens. It even goes down to a negative value.

-------

IF :SEATS_LEFT < 0 THEN

     MESSAGE('NO SEATS AVAILABLE');

END IF

-------

Tagged:

Answers

  • Sanjay Desai EBS
    Sanjay Desai EBS Member Posts: 1,779 Gold Trophy
    edited Mar 6, 2015 10:37PM

    You put following code on WHEN-VALIDATE-ITEM on all 3 Text Items.

    Following is the logic of ADULT text item for WVI trigger. Same logic you applied for CHILD & INFANT.

    declare

           v_sleft  NUMBER := 0;

    begin

        v_sleft :=  NVL(:block.seats_left,0)  ;

        v_sleft :=  v_sleft - NVL(:block.adult_passenger,0) ;   

         

        if v_sleft <= 0 THEN

              MESSAGE('NO SEATS AVAILABLE');

             raise form_trigger_failure;

         else

             :block.seats_left :=  v_sleft ;

        end if;

    end;

  • ayadsufyan
    ayadsufyan Member Posts: 176 Bronze Badge
    edited Mar 8, 2015 4:38PM

    I agree with  Sanjay , or

    you can use a text item  and assigne its   update_allowed and insert_allowed  to False

    and put your code in the when_validate_item

    IF NVL(:SEATS_LEFT,0) < 0 THEN

         MESSAGE('NO SEATS AVAILABLE');

         RAISE FORM_TRIGGER_FAILURE;

    END IF

  • Amatu Allah Neveen Ebrahim
    Amatu Allah Neveen Ebrahim Member Posts: 5,081 Gold Trophy
    edited Mar 9, 2015 2:05AM
    2898128 wrote:
    
    this is my form
    
    
    Untitled 1.png

    the SEATS LEFT box is a display item with a fixed to total value of 217. When I enter a value in either of the three boxes which are Adult, Child, and Infant, the SEATS LEFT will subtract the total values of those three text items.

    So I want it to stop when it reaches 0 (ZERO)  and gives a message.  I tried putting WHEN-VALIDATE AND POST_CHANGE triggers to the SEATS LEFT with this code, but nothing happens. It even goes down to a negative value.

    -------

    IF :SEATS_LEFT < 0 THEN

         MESSAGE('NO SEATS AVAILABLE');

    END IF

    -------

    Hi

    Nothing happened since the condition will never return true, pls change the logical operator of your condition from < to =

    Amatu Allah.

  • juliojgs
    juliojgs Member Posts: 596 Bronze Badge
    edited Mar 9, 2015 4:49AM

    Have you tried setting to zero the Lowest Allowed Value Property at design time?

    I think this way the error will trigger immediatly. If you don't like the FRM error message, you can trap it at on-error trigger.

This discussion has been closed.