Adding a description to an attribute

Permalink
I'm looking for a way to add a tooltip or description to custom fields during registration. I am thinking the best way to do this is to add a "description" field to attributes, and then add it to display on the register page. However this would require making some changes to the database, which I would like to avoid.

Does anybody have any tips on how to do this? Perhaps my way is not the best, I am looking for suggestions.

 
ijessup replied on at Permalink Reply
ijessup
I wouldn't not say that your way isn't not the worst way of doing it the best way...

Frankly, trying to add a description parameter to all the AttributeTypes is going to be a serious pain the in butt. However, it would be a nice feature.

My recommendation is to just add some JS to the registration page to apply the tool tips. Look at the name and id attributes of all the input fields. They will looks something like...

akID[21][value]

...where 21 is the attribute key's ID. Use this identifier to apply the tool tips via JS or even with jQuery.
jgaris replied on at Permalink Reply
For now I am attempting to create a custom attribute that is a modified copy of the Text type, adding a description field. However I think it would be useful if it was added to all attribute types.
Shotster replied on at Permalink Best Answer Reply
Shotster
I was going to suggest a client-side solution similar to ljessup, but then another quick and dirty approach came to mind which should provide an easy way to specify tooltips for any attribute type.

The basic idea is to choose a delimiter (single character or sequence of characters) that you will never use in the name of an attribute (perhaps 3 tilde characters in a row). When defining/editing the attribute in the dashboard, simply enter into the "Name" field your desired attribute name followed by your delimiter followed by the tooltip message like so:

My Custom Attribute~~~My custom attribute tooltip!

Then just override the following core files...

models/attribute/key.php
elements/attribute/type_form_required.php

In your key.php file, replace the getAttributeKeyName() method with something like the following...

<?php
   /** 
    * Returns the TRUE (unparsed) name for this attribute key for editing purposes
    */
   public function getAttributeKeyNameActual() {
      return $this->akName;
   }
   /** 
    * Returns the name for this attribute key
    */
   public function getAttributeKeyName() {
      $a = explode('~~~', $this->akName);
      return( $a[0] );
   }
   /**

In your type_form_required.php file change the getAttributeKeyName() call to getAttributeKeyNameActual().

When you want to access the tooltip from code, just call the getAttributeTooltip() method.

Seems to work well, but I haven't tested it extensively.

-Steve
ScottC replied on at Permalink Reply
ScottC
i'd add the additional field in the db as ibjessup recommends.
Shotster replied on at Permalink Reply
Shotster
> i'd add the additional field in the db as ibjessup recommends.

Where did ljessup recommend that? I must be missing something.

-Steve
ScottC replied on at Permalink Reply
ScottC
it must have been a mirage, or wishful thinking on my part.

The right way to do it IMO is to create a new AttributeType and add the field and copy and paste and massage the standard attribute for the additional field, or you could do what you said but change the controller to the concating or exploding over your "hidden" delimiter is transparent to the end user.

That is probably the easiest way to do it instead of telling someone to add three "~" or something like that.
Shotster replied on at Permalink Reply
Shotster
Very true, but my admittedly "quick and dirty" approach avoids making changes to the DB which the OP specifically said they wanted to avoid.

-Steve
ScottC replied on at Permalink Reply
ScottC
true, i'd still take the 20 minutes to hide the implementation of it concating or json encoding the post array and pulling it back out from the end user.

Not trying to argue or anything :) I'm just saying that just a little bit of additional effort will give you a much better result.
Shotster replied on at Permalink Reply
Shotster
> a little bit of additional effort will give you a much better result.

Agreed.

-Steve
Shotster replied on at Permalink Reply
Shotster
For the record, I would never recommend my quick and dirty solution for a client site. However, I finna do it on my personal site.

:-)

-Steve
jgaris replied on at Permalink Reply
Shotster, this is exactly the type of quick and dirty option I was looking for. It worked perfect for me. Thank you.

It might not be the "best practice" method but I am selecting it as the best answer because it was exactly what I was looking for.