By Jeffrey04 on
I need to apply some Javascript code to the user profile page and hence I need some of the custom fields in user profile to be given specific class names. However, I don't find it possible with the profile module. I would like to know whether I can extend the profile module to include new field types or there is a simpler solution to this problem?
Comments
Can you use the field id?
The fields are all give id's, so this appears to be a cleaner way of hooking the form fields.
e.g.
Looking at the profile module, (just a 10 second scan), I can not see a simple clean way of adding a class.
Alan Davison
www.caignwebs.com.au
Alan Davison
thanks for the information.
thanks for the information. Anyway I am going to use YUI with Drupal, the dollar sign function seems to be a prototype/jQuery function right? I would probably going to change my javascript code a bit to allow it to collect field id as well.
JQuery rocks
I'd suggest looking at some reference sites for jquery. It's a very powerful library and is core to the javascript routines used in Drupal. It has a number of selectors, either id, class or pretty much anything else. (Xpath based)
It makes javascript real easy.
Alan Davison
www.caignwebs.com.au
Alan Davison
YUI has similar features as
YUI has similar features as well, it is just that I want to use my current javascript app directly without modifying the existing code (yes, I'm lazy)....
I have just found out this
I have just found out this http://drupal.org/node/101092
Can I do something similar? like create a template for the new profile fields to override the default template? Then modify the field a bit to include the desired class name?
Wouldn't this be easier?
You can assign classes to the fields based on their id, either individually or as a group:
Supa easy
Alan Davison
www.caignwebs.com.au
Alan Davison
the problem with this is I
the problem with this is I would have to do it manually whenever I have a new field that needs to call the javascript. It can be done with YUI as well
var some_element = YAHOO.util.Dom.get('edit-profile-test');
YAHOO.util.Dom.addClass(some_element, 'my-class-name');
maintenance will be a big problem here, imagine if you constantly have to add new fields or delete existing fields......
You can use form_alter to modify the form
This can be partially automated by hooking into HOOK_form_alter. In the example below I have a profile category "Personal Info" and a single field "profile_test".
which produces this js in the header:
If you use a strict naming convention, then this can be checked to decide if the class(es) should be added.
Eg:
Alan Davison
www.caignwebs.com.au
Alan Davison
thanks
thanks