How to conditionally display Form items when changing the row in a Grid

How do you get to conditionally display form items, when changing the row within a grid? It’s a request that one of our users had a while back. Here’s the use case:

I have a grid which displays rows that represent an image or a document. The grid is bound to a form (via Master-Detail) and the form shows the fields that can be edited. 

The issue I encounter is: if the item is an image, then I want to show up the field P901_DOC_CONTENT_BILD in the form and hide the page item P901_PREVIEW. If it’s a document (PDF, DOC, XLS etc.), then I want to hide the image field (P901_DOC_CONTENT_BILD) and show up P901_PREVIEW which makes a HTML preview.

I have tried to change a page item’s value to 1 / 0, when a new row is selected in the grid, but couldn’t find the right event to manage this. 

There are two solutions available in order to conditionally display form items, given the above use case:

 

Solution #1

We can use a hidden page item to hold the status of what to show/hide. Then add conditions on our items using a PLSQL Expression. For example:

1-foex-form-hide-show-items-hidden-item

 

Sample:

begin
  if ks_doc.is_bild (:P901_ID_DOC) then
     RETURN 0;
  else
     RETURN 1;
  end if;
end;

 

Next, on the items we want to hide/show control using this value we’ll add a PL/SQL condition, as seen below:

2-foex-form-hide-show-items-condition

 

Sample:

(:P901_SHOW_PREVIEW = 1) OR NOT fx_p_form_api.is_processing

 

The reason why we need to use OR NOT fx_p_form_api.is_processing is to make sure that the page item is included on the page when it is rendered. If the item fails this condition when the page gets rendered, then it will be excluded from the page entirely.

The left side of the expression written above is for the form to automatically hide/show the item based on the result, after every form load/save.

 

Solution #2

We can use a hidden page item to hold the status of what to show/hide and then use conditions on our items using a PL/SQL Expression. For example:

3-foex-form-hide-show-items-hidden-item

 

Sample:

begin
  if ks_doc.is_bild (:P901_ID_DOC) then
     RETURN 0;
  else
     RETURN 1;
  end if;
end;

 

Next, we’ll use a dynamic action to control the hiding/showing of items.

4-foex-form-hide-show-items-da

5-foex-form-hide-show-items-action

 

And we’re done! Of course, you can use either of the two solutions shown above, but we  do recommend that you use the one that you find easier to understand and manage.

 

Do you have a technical question about FOEX or want good tips for improving your application? We’ve launched this series of How To articles to help improve your FOEX applications even more.

Use #askFOEX on Twitter and we’ll get back to you as soon as possible or sign up for a free trial and see why it is a great tool for developing large-scale web applications!

Add your comment

Your email address will not be published. Required fields are marked *