5 Replies Latest reply: Feb 20, 2013 11:56 AM by CraigB RSS

    Disable or enable the button based on other text item value

    987536
      Hi all,
      i am facing some problem in oracle forms development.

      I have one query find form that contain 2 fields(customer name and customer number).i have a requirement that FIND button in the form need to enable only if any one of the search field contain data.
      I wrote a trigger in WHEN VALIDATE ITEM of both search field

      that is
      -- customer number
      IF customer_ number is not null then
      Set_item_property('query_find.customer_number,enabled,property_true);
      elsif customer_ number is null and customer_ name is null
      then
      Set_item_property('query_find.customer_number,enabled,property_false);
      end if;

      --customer name
      IF customer_ name is not null then
      Set_item_property('query_find.customer_number,enabled,property_true);
      elsif customer_ number is null and customer_ name is null
      then
      Set_item_property('query_find.customer_number,enabled,property_false);
      end if;

      this create a problem when i entered the data it works fine but when i remove the data in both the field, after control goes to some other area of the form then only find button gets disable.

      i tried the same thing in POST TEXT ITEM,PRE TEXT ITEM,POST CHANGE trigger.

      i want once the data is completely removed in second field, at the same time it need to disable.

      please help me to resolve the issue

      Thanks and regards,
      Karthik M

      Edited by: 984533 on Feb 19, 2013 9:32 PM
        • 1. Re: Disable or enable the button based on other text item value
          Amatu Allah Neveen Ebrahim
          Hi
          Sounds ur block is single record for search input then u need to use...
          To_Char or To_number if u Will compare 2 items then same datatype is needed for comparison otherwise write each in separate statement.
          Since i don't know what is ur datatype is then u have to decide .
          the following is just an example...

          WHEN NEW BLOCK INSTANCE or PRE BLOCK Trigger block level
          IF :CUSTOMERS_NAME OR :CUSTOMERS_code IS NULL THEN
          
           set_item_instance_property('block_name.button_name',enabaled,property_off);
          
          ELSIF .......
           set_item_instance_property('block_name.button_name',enabaled,property_on);
          END IF; 
          Another idea is to use set_item_instance_property with navigable set to FALSE look for it inform on line help

          Amatu Allah
          • 2. Re: Disable or enable the button based on other text item value
            CraigB
            Karthik,
            Your code doesn't make sense to me.
            -- customer number
            IF customer_ number is not null then
            Set_item_property('query_find.customer_number,enabled,property_true);
            elsif customer_ number is null and customer_ name is null
            then
            Set_item_property('query_find.customer_number,enabled,property_false);
            end if;
            Why are you trying to set CUSTOMER_NUMBER enabled if it is not null? It stands to reason that if the field has a value entered in it, then it is ENABLED. You do this with the CUSTOMER_NAME field also. Your search fields should always be enabled unless they are dependent on one another.
            this create a problem when i entered the data it works fine but when i remove the data in both the field, after control goes to some other area of the form then only find button gets disable.
            I think your best option would be to enable/disable your Search button in the QUERY_FIND block's When-New-Item-Instance trigger. Something like:
            /* Sample When-New-Item-Instance trigger */
            BEGIN
              IF ( :QUERY_FIND.CUSTOMER_NAME IS NULL AND :QUERY_FIND.CUSTOMER_NUMBER IS NULL ) THEN 
                Set_Item_Property('QUERY_FIND.SEARCH_BTN', ENABLED, PROPERTY_FALSE);
              ELSE
                Set_Item_Property('QUERY_FIND.SEARCH_BTN', ENABLED, PROPERTY_TRUE);
                Set_Item_Property('QUERY_FIND.SEARCH_BTN', NAVIGABLE, PROPERTY_TRUE);
              END IF;
            END;
            Keep in mind that when you enable an item that was disabled, you have to set the NAVIGABLE, UPDATE_NULL, and UPDATABLE properties to TRUE also. In your case, since you are enabling a button, you would just need to set the ENABLED and NAVIGABLE properties to TRUE.

            If you need Forms to respond while the event is happening (such as you want the button to enable as soon as a user starts typing in a field) then you would need to use a 3rd party Java Bean (such as the KeyEvent Java Bean) or develop your own.

            Hope this helps.

            Craig...
            • 3. Re: Disable or enable the button based on other text item value
              CraigB
              Amatu,
              IF :CUSTOMERS_NAME OR :CUSTOMERS_code IS NULL THEN
              set_item_instance_property('block_name.button_name',enabaled,property_off);

              ELSIF .......
              set_item_instance_property('block_name.button_name',enabaled,property_on);
              END IF;
              Your code sample isn't even valid syntax! There is no "ENABLED" property for the SET_ITEM_INSTANCE_PROPERTY built-in and the CONSTANT is PROPERTY_FALSE or PROPERTY_TRUE not OFF/ON!

              Craig...
              • 4. Re: Disable or enable the button based on other text item value
                987536
                Hi CraigB ,
                thank you very much for spending your valuable time for answering my question. i got more than enough information from your reply. I will try and let you know the status and if any more help i need

                thanks,
                karthik m
                • 5. Re: Disable or enable the button based on other text item value
                  CraigB
                  Karthik,
                  Glad I was able to help.

                  Happy coding...
                  Craig...