Recent Topics

BUG 6.9.x Plugin Event AdminDisplayItemFormFieldset and init_colorpicker_js()

Started by on Mar 07, 2018 – Contents updated: Mar 14, 2018

Mar 07, 2018 15:02    

When editing Items: admin.php?ctrl=items&action=edit,

Plugins provides a hook: $Plugins->trigger_event( 'AdminDisplayItemFormFieldset', array( 'Form' => & $Form, 'Item' => & $edited_Item, 'edit_layout' => 'expert' ) );

This allows the insertion of form parts.

If form input type=color is used, the JS for color picker field does not get initialized.

        // Initialize JS for color picker field on the edit item form:
        init_colorpicker_js();
BUG 6.9.x Plugin Event AdminDisplayItemFormFieldset and init_colorpicker_js()

Please can this be updated?

Mar 14, 2018 07:12

Hello @achillis, we don't want to load the files of the colorpicker on ctrl=items if there is no input type=color, i.e. when your plugin is not enabled.

So if you use a color input in your plugin like:

function AdminDisplayItemFormFieldset( & $params )
{
	$params['Form']->begin_fieldset( 'TEST plugin' );
	$params['Form']->color_input( 'color', '#F60', T_('Color'), T_('E-g: #ff0000 for red') );
	$params['Form']->end_fieldset( 'Foo' );

	return true;
}

you should also use the following code in the plugin:

function AdminEndHtmlHead( & $params )
{
	global $ctrl, $action;

	if( isset( $ctrl, $action ) &&
	    $ctrl == 'items' &&
	    in_array( $action, array( 'new', 'new_switchtab', 'copy', 'create', 'create_edit', 'create_publish', 'edit', 'edit_switchtab', 'update', 'update_edit', 'update_publish', 'extract_tags' ) ) )
	{	// Initialize JS for color picker field on the edit item form:
		init_colorpicker_js();
	}
}

You may not use the condition && in_array( $action, array( 'new', 'new_switchtab', 'copy', 'create', 'create_edit', 'create_publish', 'edit', 'edit_switchtab', 'update', 'update_edit', 'update_publish', 'extract_tags' ) ) if you really want to load the js and css files of the colorpicker on each page of the items controller, or if you are afraid to miss this for some new future actions.

Thanks.

This post has 1 feedback awaiting moderation...


Form is loading...

powered by b2evolution free blog software – This forum is powered by b2evolution CMS, a complete engine for your website.