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.
Does anybody have any tips on how to do this? Perhaps my way is not the best, I am looking for suggestions.
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.
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...
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
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] ); } /**
Viewing 15 lines of 22 lines. View entire code block.
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
i'd add the additional field in the db as ibjessup recommends.
> i'd add the additional field in the db as ibjessup recommends.
Where did ljessup recommend that? I must be missing something.
-Steve
Where did ljessup recommend that? I must be missing something.
-Steve
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.
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.
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
-Steve
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.
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.
> a little bit of additional effort will give you a much better result.
Agreed.
-Steve
Agreed.
-Steve
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
:-)
-Steve
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.
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.
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.