Hi,

Explanation:
I created a field of type "RGB Color Example" widget with the "Color Picker" in a node.

Bug
When I want to add content to this node, I can not have the "farbtastic colorpicker" for this field. Javascript error :

Erreur : f is undefined
Fichier Source : http://192.168.122.243/drupal7/misc/farbtastic/farbtastic.js?v=1.2
Ligne : 2

My Fix:
In the file examples/field_example/field_example.js (line 16)

var picker = $ (this). Closest ('div'). parent (). find (". field-example-colorpicker");

at the place of

var picker = $ (this). Closest ('tr'). find (". field-example-colorpicker");


Good day,

laurent M

CommentFileSizeAuthor
#2 examples_field_javascript.patch692 bytesilo

Comments

ilo’s picture

Thanks for reporting this imagendie. Still have to review the purpose of parent(), but nice catch.

ilo’s picture

Status: Active » Needs review
StatusFileSize
new692 bytes

ok, the div.parent() change seems to work, but I'd like to call the attention for others here.

Currently the Color picker widget will not show the Label when accepting only 1 value. When the field accepts more than 1 value, the table shows this Label in the header section. I've been playing around but I'm not sure if this is a widget's (core) bug or the example module not showing it.

webchick’s picture

Status: Needs review » Reviewed & tested by the community

This fixed the problem for me! Thanks!

lmeurs’s picture

Laurent M's solution does work fine, but could be improved on 2 levels.

1: Since closest() starts traveling with the DOM element it is called on and this element is a DIV element, $(this).closest('div') returns the same element as $(this). So:

var picker = $(this).closest('div').parent().find (".field-example-colorpicker");

could be rewritten as:

var picker = $(this).parent().next().find (".field-example-colorpicker");

or even better as:

var picker = $(this).parent().next();

2: But this script still is not prepared for other (future) situations, since it assumes the target element with class 'field-example-colorpicker' ALWAYS is on the exact same branch of the DOM tree. I prefer traveling down the DOM tree until we find a parent element that contains the target element, like this:

var picker, parent = $(this).parent();
while (parent && parent[0]) {
     var _picker = $(parent[0]).find('.field-example-colorpicker');
     if (_picker && _picker[0]) {picker = _picker[0]; break; }
     else parent = $(parent[0]).parent();
}

I think this is a little bit more future proof.

mile23’s picture

In this case, we know where the field-example-colorpicker is, because we put it into the DOM ourselves in field_example_field_widget_form() in field_example.module. It might help to point this out in comments in the javascript.

dave reid’s picture

Version: » 7.x-1.x-dev
rfay’s picture

#2: examples_field_javascript.patch queued for re-testing.

rfay’s picture

Status: Reviewed & tested by the community » Fixed

Committed #2: 97a5221a084a98d52ca86e589cf572e049937918

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.