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
Comments
Comment #1
ilo commentedThanks for reporting this imagendie. Still have to review the purpose of parent(), but nice catch.
Comment #2
ilo commentedok, 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.
Comment #3
webchickThis fixed the problem for me! Thanks!
Comment #4
lmeurs commentedLaurent 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:
I think this is a little bit more future proof.
Comment #5
mile23In 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.
Comment #6
dave reidComment #7
rfay#2: examples_field_javascript.patch queued for re-testing.
Comment #8
rfayCommitted #2: 97a5221a084a98d52ca86e589cf572e049937918