i want to add color picker in widget
https://magento.stackexchange.com/a/190260/73525
This above link is working for system config
same thing i want in widget as field
Any one have idea about this
i want to add color picker in widget
https://magento.stackexchange.com/a/190260/73525
This above link is working for system config
same thing i want in widget as field
Any one have idea about this
Try this:
<parameter name="color" xsi:type="block" required="false" visible="true">
<label translate="true">Color</label>
<block class="Vendor\Module\Block\Widget\Color" />
</parameter>
<?php
namespace Vendor\Module\Block\Widget;
use Magento\Framework\View\Element\Template;
use Magento\Widget\Block\BlockInterface;
class Color extends Template implements BlockInterface
{
public function prepareElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$defaultColor = "#8ec63f";
$value = $element->getValue() ?: defaultColor;
$element->setData('after_element_html', '
<input type="text"
style="height: 55px; width: 55px;"
value="' . $value . '"
id="' . $element->getHtmlId() . '"
name="' . $element->getName() . '"
>
<script type="text/javascript">
require(["jquery", "jquery/colorpicker/js/colorpicker"], function ($) {
$currentElement = $("#' . $element->getHtmlId() . '");
$currentElement.css("backgroundColor", "'. $value .'");
$currentElement.ColorPicker({
color: "' . $value . '",
onChange: function (hsb, hex, rgb) {
$currentElement.css("backgroundColor", "#" + hex).val("#" + hex);
}
});
});
</script><style>.colorpicker {z-index: 10010}</style>');
$element->setValue(null);
return $element;
}
}
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="jquery/colorpicker/css/colorpicker.css"/>
</head>
</page>
Do you check official documentation? https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/ui-colorpicker.html