Using jQuery UI for user interaction

JQuery UI is an additional library based on jQuery. When using the jQuery UI, always load and reference the base jQuery library. The jQuery UI adds user interface interactions and effects to the standard jQuery library, along other features.

In order to use the jQuery UI library, proceed to the following URL and download the stable release:

http://jqueryui.com/

At the time of writing, Version v1.9.1 was the most current version, and it required jQuery version 1.6 or above. Always make sure your jQuery library is in conformance with the requirements for jQuery UI.

One of the most used widget in this library is the tooltip widget. In this recipe we will look at how to use it in the context of Dynamics CRM.

Getting ready

For this recipe we will continue to use the previously created solution package. If you are starting fresh you can create a new solution package. We will implement our customization on the Contact entity.

How to do it...

If we are using the previously created solution, we already have the jQuery library loaded as a web resource. Otherwise, you have to load it.

  1. Open your existing solution.
  2. Add a new web resource. Name it crm_jqueryui. Browse to the jQuery UI script file and load it.
  3. Save and Publish your web resource.
  4. Add a new web resource of type CSS. The jQuery UI comes with an associated CSS file you need to also load. Name this web resource as crm_jqueryuicss.
  5. Save and Publish the web resource.
  6. In the same web resource where we added all the previous functions, add a new function as follows:
    function MiddleNameTooltip()
    {
      var _css = "/WebResources/crm_jqueryuicss";
      var cssref = document.createElement("link");
      cssref.setAttribute("rel", "stylesheet");
      cssref.setAttribute("type", "text/css");
      cssref.setAttribute("href", _css);
      $("head").append(cssref);
      var _obj = document.getElementById("middlename_d").children[0];
      _obj.title = "";
      $("#middlename_d").tooltip({ content: "Enter your Middle Name" });
      $("#middlename_d").tooltip({ position: {my: "left+15 center", at: "left center"} });
      $("#middlename_d").tooltip("option", "content", "Enter your Middle Name" );
      $("#middlename_d").tooltip("option", "position", {my: "left+15 center", at: "left center"} );
    }
  7. Add the jQuery and jQuery UI resources to the form library.
  8. Associate the MiddleNameTooltip function with the form's OnLoad event of the main contact form.
  9. Save the form and close it.
  10. Save and Publish your solution.
  11. Now test your changes by opening a contact and pointing your mouse at the Middle Name field. You should see a result as shown in the following screenshot:
    How to do it...

How it works...

First off, our function adds the reference to the CSS file that comes with the jQuery UI library. We load it in the head section of the form.

Next, using the standard HTML DOM we define a blank title to the field where we want to show a tooltip.

Note

Note that defining a title with text content for a field is sufficient to make it show a tooltip using the default Dynamics CRM formatting. We are using jQuery UI in this example to take advantage of the advanced formatting of tooltip.

The following lines initialize and set the tooltip content and position. You can play around with the position to locate the tooltip at various locations relative to the page or the control with which you are associating the tooltip.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.166.75