Jump to content

Show or Hide div based on field being null or not


Recommended Posts

Thought others might find this useful. If you have a complicated table (using separate html blocks for the tr,td, etc) set up in a Details report you're unable to use Rules to show/hide sections. Because if a Section is inside the overall table (between the html blocks with table,tr,td) then when hidden it hides the entire table and therefore all of your fields within it. This is really a problem in terms of being able to have 'smart' reports. 

A workaround is to put a div in an html block and then show/hide it based on whatever criteria you would have used in a Rule. In this example that would be using a field that's a number and judging if it's null/not-null. 

So instead of a rule use 2 divs to show/hide what you want. The 1st div has it's own objects (and you could put virtual fields, regular fields, buttons, etc within it) and the 2nd div shows different objects (or it could just be text or blank if desired). 

Here's what to do:

 

The field for the criteria needs to be on the results list and in this example is a number value, set to 'Hidden.'

 

In an html block uncheck the html editor.

Use section id's for the divs:

<div id="section1">Objects specific to this div</div>
<div id="section2">Objects specific to this div, or blank if desired</div>

 

Then in the footer put your code:

<script>
   var v_divhideid = parseFloat(document.getElementById("EditRecordMyFieldName").value);

if(!isNaN(v_divhideid))
{
  document.getElementById('section1').style.display = "block";
  document.getElementById('section2').style.display = "none";
}
else
{
  document.getElementById('section1').style.display = "none";
  document.getElementById('section2').style.display = "block";
}
</script>

 

This enables you to show different objects depending on the value of a field, like a Rule, but using divs instead. 

 

Link to comment
Share on other sites

On 2/10/2017 at 4:46 PM, DesiLogi said:

Thought others might find this useful. If you have a complicated table (using separate html blocks for the tr,td, etc) set up in a Details report you're unable to use Rules to show/hide sections. Because if a Section is inside the overall table (between the html blocks with table,tr,td) then when hidden it hides the entire table and therefore all of your fields within it. This is really a problem in terms of being able to have 'smart' reports. 

A workaround is to put a div in an html block and then show/hide it based on whatever criteria you would have used in a Rule. In this example that would be using a field that's a number and judging if it's null/not-null. 

So instead of a rule use 2 divs to show/hide what you want. The 1st div has it's own objects (and you could put virtual fields, regular fields, buttons, etc within it) and the 2nd div shows different objects (or it could just be text or blank if desired). 

Here's what to do:

 

The field for the criteria needs to be on the results list and in this example is a number value, set to 'Hidden.'

 

In an html block uncheck the html editor.

Use section id's for the divs:

<div id="section1">Objects specific to this div</div>
<div id="section2">Objects specific to this div, or blank if desired</div>

 

Then in the footer put your code:

<script>
   var v_divhideid = parseFloat(document.getElementById("EditRecordMyFieldName").value);

if(!isNaN(v_divhideid))
{
  document.getElementById('section1').style.display = "block";
  document.getElementById('section2').style.display = "none";
}
else
{
  document.getElementById('section1').style.display = "none";
  document.getElementById('section2').style.display = "block";
}
</script>

 

This enables you to show different objects depending on the value of a field, like a Rule, but using divs instead. 

 

Thanks for sharing!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...