EMC Developer Network

Hide Seconds, Minutes and/or Hours in the WDK Date-Time control

January 2006
Contributed by - Michael S. McCollough, Developer, michael.mccollough@fftechnologies.com, Forefront Technologies

Software Environment

FeatureTested on
Operating SystemNA
CompilerNA
RuntimeJavascript
DFC5.x
Content Server5.x
WDK5.2.5 SP2,SP3, 5.3 SP1

Abstract

Javascript that allows you to hide the hour, minute, or seconds of the docbaseattribute time control without having to delve into customizing the control class. This script also gets rid of the corresponding colons and the commas after the each control. This script has been tested with 5.2.5 and 5.3.

Snippet


/* Function hideTimeControls(hideControls, attributeName) 
* takes a String array of hour, minute, or second and the attribute 'title' to make the
* control(s) invisible. Minutes should not be hidden by themselves as it will leave a 
* hole in its place. Format is okay with removing Hour, Seconds, or Minutes/Seconds
* but not minutes by itself.
*
* If you want to remove all hour, minute, and or second controls, 
* you can pass hour, minute, or second or all 3
*
* 
* Script Include Example:
* <script language="javascript" 
* src='<%=Form.makeUrl(request, "/custom/library/scripts/utils.js")%>'>
* </script>
*
* Usage Example: 
* This hides all minute and second controls on the page
* <dmf:body cssclass="contentBackground" onload="hideTimeControls([\"minute\",\"second\"]);">
*
* This hides the second control for the attribute whose label is "Last Review Date"
* <dmf:body cssclass='contentBackground' id='attributes_dm_document' 
*        titlenlsid='MSG_TITLE' onload="hideTimeControls([\"Last Review Date Second\"]);">
*
* @author Michael S. McCollough (Forefront Technologies)
*
*/

function hideTimeControls(hideControls) {
var i;
var c;
var bodyControls;

bodyControls= window.document.all; 

for (i=0;i < bodyControls.length;i++)
{
	for (c=0;c<hideControls.length;c++) 
	{
		var element = bodyControls.item(i);		
		if(element.name != null) 		
		{
			if( (element.name.toLowerCase().indexOf(hideControls[c])!=-1) ) 
			{
				element.style.visibility="hidden";
				element.replaceAdjacentText("beforeBEGIN","");
				if( hideControls[c].indexOf("hour") !=-1) 
				{
					var elParent = element.parentElement.parentElement;
					var tdElements = elParent.getElementsByTagName("TD");
					if(tdElements != null) 					
					{
					   for (e=0;e<tdElements.length;e++) 
					   {
						   if(tdElements[e].innerText != null) 
						   {
						      if(tdElements[e].innerText.indexOf(",") !=-1) 
							  {
							      elParent.removeChild(tdElements[e]);
							  }
						   }						   
					   } //end for iteration of tdElements
					}//end null check for tdElements
				} //end check for removal of hour control
			}
		}
	}
}//end form iteration 
} //END function hideTimeControls

	

Using the Code

Takes a String array of hour, minute, or second and the attribute name to make the control(s) invisible. Minutes should not be hidden by themselves as it will leave a hole in its place.

Note:The above code demonstrates a specific piece of functionality and is not meant to be a complete solution

Enhancement

An enhancement suggested by Ingo Zitzmann is to set the to set the display property to 'none' instead of setting the visibility to hidden.


...
//element.style.visibility="hidden";
element.style.display="none";
...

By using display="none" it removes the tags completely without leaving an "empty space". Simply putting them as hidden might cause problems aligning columns and such as the hidden controls still take up space.

The control has been tested with the WDK docbaseattributelist and docbaseattributevalue controls . To use the script, include it in a page containing the above controls and add the onload event handler in the dmf:body tag. Please see the code above for usage examples.