It seems that advance modules are a bit easier to work with than the simple modules given my background of working with a similar setup of the advance modules type. Now, I know how to add javascript to the simple modules but what about adding css? What I want to do is add a colorpicker plugin that works with jquery however it does require the css. Is there a way to inject css like the js? Thanks in advance.
Comments
http://docs.getfuelcms.com/general/forms#association_parameters
Here is what I have added to my custom_fields.php,
$fields['my_custom_field'] = array(
'colorpicker' => array(
'js_function' => 'ColorPicker',
'css' => array(
'colorpicker/colorpicker',
'colorpicker/layout'
),
'js' => array(
'colorpicker/colorpicker',
'colorpicker/eye',
'colorpicker/utils',
'colorpicker/layout.js?ver=1.0.2'
)
)
);
Now, what I was wanting to do, is apply type 'colorpicker' and then the field would automatically show the colorpicker as in the jquery plugin documentation. I can't seem to understand the custom fields docs on this. Thanks for the help admin.
$fields['colorpicker'] = array( 'js_function' => 'ColorPicker', 'css' => array('colorpicker/colorpicker', 'colorpicker/layout'), 'js' => array('colorpicker/colorpicker', 'colorpicker/eye', 'colorpicker/utils', 'colorpicker/layout.js?ver=1.0.2') );
In my simple module model file, I have a type of 'colorpicker'.
In the custom fields file, I have this:
$fields['colorpicker'] = array(
'class' => array(FUEL_FOLDER => 'Fuel_custom_fields'),
'function' => 'colorpicker',
'css' => array(
'colorpicker/css/colorpicker.css',
'colorpicker/css/layout.css'
),
'js' => array(
'colorpicker/js/colorpicker',
'colorpicker/js/eye',
'colorpicker/js/utils',
'colorpicker/js/layout.js?ver=1.0.2'
)
);
Then in the Fuel_custom_fields:
function colorpicker($params)
{
$form_builder =& $params['instance'];
$js = '
$(document).ready(function(){
$(".field_type_colorpicker").ColorPicker({flat: true});
});
';
$form_builder->add_js($js);
return $form_builder->create_text($params);
}
Still don't get the colorpicker to show.
1. There was a bug with loading multiple CSS files for custom fields. I've pushed an update for that to the 1.0 branch so grab the latest.
2. Place the colorpicker css files into an assets/css/colorpicker/ folder and change all image paths to go ../../images. You will need to alter the z-index of the .colorpicker class to be something like 10. Also, don't include the layout.css.
3. Simalarly with the javascript, add the colorpicker js to an assets/js/colorpicker folder. Don't include the layout.js.
4. I wouldn't recommend adding to the Fuel_custom_fields because it makes it difficult to update going forward. Instead, you can create your own class and put it in your fuel/application/libraries/ folder. I added a MY_custom_fields.php class with the following:
class MY_custom_fields { function colorpicker($params) { $form_builder =& $params['instance']; $js = '<script type="text/javascript"> $(function(){ $(".field_type_colorpicker").ColorPicker({ onSubmit: function(hsb, hex, rgb, el) { $(el).val(hex); $(el).ColorPickerHide(); }, onBeforeShow: function () { $(this).ColorPickerSetColor(this.value); } }) .bind("keyup", function(){ $(this).ColorPickerSetColor(this.value); }); }) </script> '; $form_builder->add_js($js); $params['class'] = (!empty($params['class'])) ? $params['class'].' field_type_colorpicker' : 'field_type_colorpicker'; $params['type'] = 'text'; return $form_builder->create_text($params); } }
3. In the fuel/application/config/custom_fields.php file, I had the following:
$fields['colorpicker'] = array( 'class' => 'MY_custom_fields', 'function' => 'colorpicker', 'css' => 'colorpicker/colorpicker', 'js' => array( 'colorpicker/colorpicker', 'colorpicker/eye', 'colorpicker/utils' ) );
Try that out and see if it works.