Field Formatting

Field formatting hooks control the formatting of field values for display. I.e., they take a raw data value (as fetched from the database), and convert it for display. All field output in Pedserve goes through these hook functions. There are several hooks, but the most important one is hookField_RenderNonKeyValue_AsHTML.

hookField_RenderNonKeyValue_AsHTML returns the HTML rendition of a field value for a data field.

The sample code below modifies the default rendition of the date field so that, if the year is 1970-1979, it appends a bullet image to the returned HTML. This single change will affect all places that convert a field to HTML within Pedserve, so it will affect the display of pedigrees, search results, etc. As you will see if you enlarge the sample screenshots to the right. Of course, this is not a real world example but it shows you how easy it is to slot in specialist field formatting code to the system, and have it apply in all report screens.

# Return the HTML rendition of a field value for a field that
# is NOT a key - a REAL data field.
#
# Arg 1 - field name prefix, with trailing . (or, empty string)
# Arg 2 - field name
# Arg 3 - context
# Arg 4 - primary key value
# Arg 5 - reference to a map containing field values
# Arg 6 - reference to a map holding field formatting options
# OPTIONAL
# Arg 7 - reference to map for future additional arguments; possibly undefined
sub hookField_RenderNonKeyValue_AsHTML {
   my ($strFldNamePrefix, $strFldName, $strContext, $nPrimaryKey,
       $rmFldValues, $rmOptions, $rmArgsEx) = @_;

   # We first simply defer to the standard implementation:
   my $htmlRet = &pdsHookStdImpl_Field_RenderNonKeyValue_AsHTML(
          $strFldNamePrefix, $strFldName, $strContext, $nPrimaryKey, 
                  $rmFldValues, $rmOptions, $rmArgsEx);

   # If this is the DOB field, then we are going to customize it:
   if ($strFldName eq 'A_DOB') {
      # Our example extracts the DOB of the animal, and if it is in the
      # 1970's, adds a bullet image to the returned HTML.
      # Of course, this is not a real-world example, but it shows how you
      # can access any of the returned field values and work with them to
      # customize what is returned.
      my $strValueKey = $nPrimaryKey.':'.$strFldNamePrefix.'A_DOB';
      if (defined($$rmFldValues{$strValueKey})) {
         # Get the DOB:
         my $strDOB = $$rmFldValues{$strValueKey};
         if ($strDOB =~ m/^197.*/) {
            # Its 197x.
            # Add a bullet to the HTML to be returned
            $htmlRet .= ' ';
            $htmlRet .= $::g_q->img({'-src' => 
                                    &pdsMakeStaticFileURL('pedserve-s1.gif')});
         }
      }
   }

   return $htmlRet;
}

Custom Field Rendering Hook - Pedigree
Custom Field Rendering Hook - Pedigree


Custom Field Rendering Hook - Search Results
Custom Field Rendering Hook - Search Results

USEFUL LINKS:
 EULA
 Pedserve Editions
 Sample City
 Consultancy
 Data Preparation
 Installation
 Regular Expressions
 Similarity Searching
 Configuration File
 Setup Script
 Stylesheet
 Database Design
 Hooks
 Date/Time
 User Defined Fields
 User Defined Records
 Display Fields Definitions
 Ordering Fields Definitions
 Highlighting
 Page Layout
 Field Definitions
 Field Formatting
 Shortcut Query Buttons
 Plates
 Command Buttons
 Connecting to the Database
 Warning Footer Message