I have colorpickers on a plugin settings page, but was wondering if it is possible to add one to an activity setup on the mod_form.php page. Is it possible with or without $mform.
I currently have a color setting on mod_form.php by using $mform->addElement('text', ....etc. but would like to use a colorpicker so I don't need to look up hex color codes.
If you're doing a plugin settings page, you can use the settings.php file and add the admin_setting_configcolourpicker class.
$setting = new admin_setting_configcolourpicker($name,
$visiblename, $desc, $defaultsetting, $previewconfig, $usedefaultwhenempty);
Thanks for the reply. I already have a colorpicker setup and working on the plugin settings page using code similar to what you provided. The problem is that only an admin can make those color changes.
I want a teacher to be able to change the color setting for the activity when they add it into a course. I do have that setup and working on the mod_form.php page, but it is just a plain text entry box so the teacher has to type in a hex color code or a color name. e.g. #95FC89, red, pink, lightgreen, etc. It would be much simpler and faster if I could use a color picker to do the entry with.
Ah right, well, you could still use the Moodle colour picker. This is a line from the colour picker class I mentioned above:
$PAGE->requires->js_init_call('M.util.init_colour_picker', array($this->get_id(), $this->previewconfig));
So you could call that from your plugin lib.php just replace $this->get_id() with the id of your text box, and previewconfig, not sure, I don't think you need that.
* Designed to be used with admin_setting_configcolourpicker although could be used
* anywhere, just give a text input an id and insert a div with the class admin_colourpicker
* above or below the input (must have the same parent) and then call this with the
* This code was mostly taken from my [Sam Hemelryk] css theme tool available in
* contrib/blocks. For better docs refer to that.