Archive for javascript
Walkthrough: DVWP Tooltip
Posted by: | CommentsTooltips may be implemented to greatly improve user experience in many scenarios. This walkthrough will provide a method with which tooltip functionality may be implemented on SharePoint Data View Web Parts (DVWPs) using XSL and JavaScript.
Preparation
- Open the SharePoint site in SharePoint Designer 2007
- Open the page on which the tooltip functionality will be implemented
- Enable either Split or Code view
Create the Tooltip
- Locate the DVWP in which the tooltip functionality will be implemented
- Locate the XSL template “dvt_1.rowview” within the DVWP
Example <xsl:template name=”dvt_1.rowview”> This XSL template specifies what is rendered for each List Item displayed in the DVWP. A tooltip will be rendered for eash List Item and therefore should be added to this template.
- Locate where the tooltip should appear
No consideration for spacing of the tooltip should be taken into account. The tooltip will utilize the position style value “absolute” to display over other page content. - Insert the blank tooltip
Example <div style=”position:absolute;display:none;margin-top:14px;white-space:
»nowrap;overflow:visible;border:silver 1px solid;background-color:
»white” class=”ms-listdescription”>
<xsl:attribute name=”id”>tooltip_<xsl:value-of select=”@ID”/>
»</xsl:attribute>
<xsl:attribute name=”onmouseenter”>javascript:this.style.display=
»’none’;</xsl:attribute>
</div>» – unintended line break The tooltip may be any HTML object and is not limited to the DIV object. The tooltip HTML object must have the id attribute set as shown in the provided example. The position and display style attributes should be set as shown in the provided example. Setting the position style attribute to “absolute” allows the tooltip to display over other page content. The onmouseenter attribute (as shown in the provided example) hides the tooltip if the user moves the cursor onto the tooltip.
If multiple DVWPs on the same page will use the tooltip functionality, the id attribute of tooltips must be made distinct in each DVWP. For example, tooltips in a DVWP on the List “Transactions” could use the id attribute convention: tooltip_transactions_[List Item ID]. Thus, tooltip id attributes that may have been “tooltip_14″ and “tooltip_14″ may now be “tooltip_transactions_14″ and “tooltip_reports_14″.
- Set the tooltip text
Example <xsl:choose>
<xsl:when test=”string-length(string(@Tooltip))=0″>
<xsl:text>No tooltip.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=”@Tooltip” disable-output-escaping=”yes”/>
</xsl:otherwise>
</xsl:choose>If the tooltip references a List Item column that is not required (i.e. may be empty), it is suggested that empty values be handled as shown in the provided example. List columns must be referenced by their internal name. Setting the disable-output-escaping attribute to “yes” will display special (i.e. escaped) characters properly (i.e. unescaped). Please note that the provided example references a custom (i.e. non-standard) column called “Tooltip”.
The tooltip should be located like:
As a result of setting the position style attribute to “absolute”, the tooltip renders like:
Create the Tooltip Triggers
- Locate the DVWP in which the tooltip has been created
- Locate the XSL template “dvt_1.rowview” within the DVWP
Example <xsl:template name=”dvt_1.rowview”> This XSL template specifies what is rendered for each List Item displayed in the DVWP. Each tooltip trigger (i.e. system response to a user action) will show /hide the tooltip in the same row (i.e. TR object) as itself. Therefore, the tooltip trigger should be located within this template.
- Locate the HTML object that will trigger the display of tooltips in response to a specified user action.
- Insert the tooltip triggers
Example <td>
<xsl:attribute name=”onmouseenter”>javascript:var tooltipObj=document.
»getElementById(‘tooltip_<xsl:value-of select=”@ID”/>’);tooltipObj.
»style.left=event.clientX;tooltipObj.style.top=clientY;tooltipObj.
»style.display=”;</xsl:attribute>
<xsl:attribute name=”onmouseleave”>javascript:document.getElementById(
»’tooltip_<xsl:value-of select=”@ID”/>’).style.display=’none’;
»</xsl:attribute>
<xsl:value-of select=”@Title”/>
</td>» – unintended line break Tooltip triggers are inline JavaScript that find and display the tooltip appropriately. The tooltip is shown by setting its display style attribute to null and hidden by setting its display style attribute to “none”. The provided example shows the tooltip when the user moves the cursor onto the Title column’s parent TD and hides the tooltip when the user moves the cursor off the title column’s parent TD. Please note that the tooltip triggers are applied to the column’s parent TD to provide an optimal user experience. The provided example displays the tooltip at the point where the user moved the cursor onto the parent TD (rather than always below the parent TD content).
Example
Show Elapsed Modified Time in a Document Library
Posted by: | CommentsIntroduction
The requirement has come to fruition to see the elapsed time from the “Modified Date” to “Now” on a reports document library. This is not possible in a calculated value unfortunately do to [Today] and [Me] values being consumed in a calculated value are considered “Volatile” by SharePoint out of the box. These use the core MOSS/WSS functions and since the list is 100% dynamic it doesn’t pull session or current state information before loading the list on page load. Every possible solution was attempted prior to using this custom solution. Although this is all “client side” customization all methods of using out of the box methods were tried prior to this solutions development, the downfall being that even when [Today] was able to be used in a calculated value it did not record the time, only the current date.
Required Items
This solution involves slight modification of Meta Data through a simple SharePoint Designer workflow, a short JavaScript function, and the creation of a “Last Updated” field that is a Date and Time field. Below are step by step instructions with screen shots of how to properly customize any List or Document Library to use this functionality. SharePoint Designer, .NET Frame Work 3.5, and WSS 3.0 are required to implement this solution.
Elapsed Time
Create or open an existing document library and go to settings.

Figure 1 Document Library Settings
Click Create Column

Figure 2 Create Column
Name the Column “Last Updated” (Red) and make it a Date & Time column (Blue)

Figure 3 Configure Column
Using Javascript to Manipulate a List Form Field
Posted by: | CommentsThis is a great post by the SharePoint Designer Team on using javascript to manipulate a list form field:
Using Javascript to Manipulate a List Form Field
Posted by: | CommentsThis is a good article on how to be able to set values on SharePoint Elements.
Thanks for the link Pirooz








