Display vs. Visibility in Dynamics CRM 4.0

Paul Nieuwelaar, 01 September 2010

You may have noticed that to make a field appear or disappear on a Dynamics CRM form you can use the JavaScript Display or Visibility. But often when you want to hide a field it is hard to know which one to use.

Display:
When using Display, the field being changed will be added or removed from the flow of the form, which means if it is not being displayed the field around it will move to fill in the space the field left behind. The same applies when the field is being displayed; in that the fields below it move down to make room for the field being displayed.

Using display is good for when you don’t want there to be an empty white space where the field used to be when it is not being displayed, however it means all other fields below it move up or down, and can be confusing for users.

If you set a field to not be displayed, and if there are any fields to the right of it, they will move left to fill in the space. If there are no fields to the right of it, the fields below will move up one line to fill up the empty line.

The code for using Display is as follows:

// Displayed

crmForm.all.fieldname_c.style.display = "inline";

crmForm.all.fieldname_d.style.display = "inline";

 

// Not Displayed

crmForm.all.fieldname_c.style.display = “none”;

crmForm.all.fieldname_d.style.display = “none”;

 

Visibility:
When using Visibility, the field being changed will not be added or removed from the flow of the form, instead it will just leave a space when it is hidden, and all fields below will not move into its place, and when it is visible again, it will occupy the same space that it left when it was hidden.

Using visibility is good for when you do not want to disrupt the positioning of other fields on the form, it will be easier for users to follow what is happening, and will be less confusing.

When setting a field to be hidden, any fields to the right it will stay where they are, and will not move left to fill in the space, instead a white space will be left. If there is no fields to the right, then the line that the hidden field is on will be left blank, and any fields below it will not move up to fill in the space.

The code for using Visibility is as follows:

// Visible

crmForm.all.fieldname_c.style.visibility = “visible”;

crmForm.all.fieldname_d.style.visibility = “visible”;

 

// Hidden

crmForm.all.fieldname_c.style.visibility = “hidden”;

crmForm.all.fieldname_d.style.visibility = “hidden”;

 

When I am hiding fields I try and use Visibility when possible, but when it will leave a blank line in its place, some times using Display is more appropriate. It’s up to you which one you use, but hopefully this will give you some ideas of where and when to use each.