Tutorial - Dropdown Inline Edit

Documentation for a historical release of Infusion: 1.3
Please view the Infusion Documentation site for the latest documentation.
If you're looking for Fluid Project coordination, design, communication, etc, try the Fluid Project Wiki.

Tutorial - Dropdown Inline Edit



Step 1: Prepare your markup

Let's assume that you're working with some HTML that displays the detailed information about a CD in your collection - something simple like this:

<dl> <dt>Artist</dt> <dd>Portishead</dd> <dt>Album</dt> <dd>Third</dd> <dt>Year</dt> <dd>2008</dd> <dt>Genre</dt> <dd>Triphop</dd> <dt>Play Length</dt> <dd>49 min 13 s</dd> <dt>Label</dt> <dd>Universal Music</dd> </dl>

The Changes

That's all - these are the only changes you need to make to your HTML.


Step 2: Write the script

The script needed to instantiate the Inline Edit Dropdown component will look like this:

jQuery(document).ready(function () { fluid.inlineEdit.dropdown("#albumGenre"); });

This function will look inside the element with the "albumGenre" ID (in this case, your <dd> element) for anything with the flc-inlineEditable class, and convert everything it finds into a Dropdown Inline Edit field with the appropriate options.

By putting the initialization function inside the jQuery(document).ready() call, you ensure that all of your markup is ready before you try to initialize the Inline Edit components.

This script can also be placed in a <script> block at the end of your document.


Step 3: Add the Fluid library to your HTML

You'll need to add the Fluid library and the jQuery Selectbox Plugin to you HTML file. Note that the jQuery selectbox plugin is currently found in the tests folder of the Fluid Infusion bundle. In the header of the file, link to the Javascript files with <script> tags:

<script type="text/javascript" src="infusion/InfusionAll.js"></script> <script type="text/javascript" src="infusion/tests/manual-tests/lib/jquery/plugins/selectbox/jquery.selectbox-0.5.js"></script>

NOTE that the InfusionAll.js file is minified - all of the whitespace has been removed, so it isn't really human-readable. If you're using the source distribution and you want to be able to debug the code, you'll want to include each of the required files individually. This would look like this:

<script type="text/javascript" src="infusion/lib/jquery/core/js/jquery.js"></script> <script type="text/javascript" src="infusion/lib/jquery/ui/js/ui.core.js"></script> <script type="text/javascript" src="infusion/lib/jquery/plugins/tooltip/js/jquery.tooltip.js"></script> <script type="text/javascript" src="infusion/framework/core/js/jquery.keyboard-a11y.js"></script> <script type="text/javascript" src="infusion/framework/core/js/Fluid.js"></script> <script type="text/javascript" src="infusion/components/inlineEdit/js/InlineEdit.js"></script> <script type="text/javascript" src="infusion/components/inlineEdit/InlineEditIntegrations.js"></script> <script type="text/javascript" src="infusion/tests/manual-tests/lib/jquery/plugins/selectbox/jquery.selectbox-0.5.js"></script>

But all of these individual files are not necessary to make it work - the InfusionAll.js and jquery.selectbox.js files are everything you need.

So that's it! That's all you need to do to add the Dropdown Inline Edit functionality to your table cells.

BUT: If you look at the file in a browser now, it doesn't look any different than it looked before - there's no way to tell that the album titles are editable. That's what the styles are for.


Step 4: Apply styles

The Dropdown Inline Edit component uses the jQuery selectbox plugin and currently requires the CSS that is shipped with the plugin. Note that right now this CSS is available in the tests directory of the Fluid Infusion bundle. We can use the Fluid Skinning System (FSS) CSS skin files alongside the selectbox plugin CSS files.

<link rel="stylesheet" type="text/css" href="infusion/framework/fss/css/fss-layout.css" /> <link rel="stylesheet" type="text/css" href="infusion/framework/fss/css/fss-theme-mist.css" /> <link rel="stylesheet" type="text/css" href="infusion/tests/manual-tests/lib/jquery/plugins/selectbox/selectbox.css" /> <link rel="stylesheet" type="text/css" href="infusion/components/inlineEdit/css/InlineEdit.css" />

and to attatch a class attribute that represents the skin you want to the components container, such as:

<dl class="fl-theme-mist"> ... </dl>

The above code would make use of the fss-theme.mist.css skin file.

If you wish to define your own styles instead, use the following information:

The Inline Edit adds classes to the display text element that can be used to style the element to let users know that the text is editable - that is, to make the functionality 'discoverable.' These classes are applied at various 'interesting moments,' for example when the cursor hovers over the editable text, or when Tab key is used to move focus to the text.

Important note

The visual appearance of the styles in the example below are just that: examples. You are free to create whatever styles you like. The important thing to understand is

  • what the interesting moments are, and

  • what the names of the styles for those moments are

The styles that are applied by the Inline Edit, and the 'interesting moments' they are used for, are:

If we add a stylesheet with these styles, the page will look like this when the mouse hovers over the album genre: