I have had need to use this field in a custom form using FAPI, so was after this feature as well.
This patch enabled me to use the defined field 'colorfield_picker' to add a colour picker field using FAPI. It also adds a field for 'colorfield_rgb' so that you can add the RGB field to a form if you wish using FAPI.
I'm getting my data from elsewhere, not from a variable, but otherwise I'm doing exactly what you're doing. Will dig deeper to try to figure out why I'm getting different results.
@lambic: Thanks for your feedback on how to get it working when used with a field (not a settings form). I will make sure your example gets included in the documentation and/or README.txt and commit the supplied patch above soon.
Comments
Comment #1
artusamakWhat would we get that we don't already have?
Comment #2
energee commentedI was looking to use this in a custom form
Comment #3
mike.davis commentedI have had need to use this field in a custom form using FAPI, so was after this feature as well.
This patch enabled me to use the defined field 'colorfield_picker' to add a colour picker field using FAPI. It also adds a field for 'colorfield_rgb' so that you can add the RGB field to a form if you wish using FAPI.
Comment #4
RaphaelBriskie commentedPatch for using the colorfield_minicolors module with the form API.
Comment #5
lambic commentedWhat's the minimum needed to make this work as a FAPI element? I tried with this:
but it didn't do anything.
Comment #6
lolandese commented@lambic:
Try to add something along the lines of
'#default_value' => variable_get('text_colour', '#000'),?It would be good if a code example for the right implementation is added to the README.txt.
Comment #7
lambic commentedGot this working, turned out to be an unrelated issue, the example in #5 does work.
Comment #8
lambic commentedComment #9
lambic commentedSpoke too soon, doesn't look like it recognises #default_value. With this:
The field does not get populated with the default value.
Comment #10
lambic commentedComment #11
lolandese commentedUse the suggestion of #6. If not, how are you going to populate the field with the value that was submitted in your form the last time?
I tested and it is working fine. I agree that '#default_value' is a bit misleading as a name. See https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen... for more info.
Comment #12
lambic commentednot sure I understand, what is the problem with my example in #9? Can you show your working example?
Comment #13
lolandese commentedHow do you store the submitted value and reproduce it on a reopened form?
Comment #14
lambic commentedhmm that's what I have except I hard-code the default for testing, not sure why mine isn't working then.
Comment #15
lolandese commentedBased on your example of #9 it should look like:
Note that the variable name should be exactly the same as the $form array key to work as expected.
Comment #16
lambic commentedI'm getting my data from elsewhere, not from a variable, but otherwise I'm doing exactly what you're doing. Will dig deeper to try to figure out why I'm getting different results.
Comment #17
lolandese commentedDo you have a code example from an existing core or contrib module that uses your same method to store and retrieve form data?
Comment #18
lambic commentedHere's my code:
The dsm gives me:
But the field appears empty when the form is rendered.
Comment #19
lambic commentedGot this working finally, with this:
Comment #20
lambic commentedComment #21
lolandese commented@lambic: Thanks for your feedback on how to get it working when used with a field (not a settings form). I will make sure your example gets included in the documentation and/or README.txt and commit the supplied patch above soon.
Comment #23
lolandese commentedAlso included an example in the README.txt.