How to add a color picker in magento 2.1.7 system config?












1















I am trying to add a color picker in magento 2.1.7 using below link but it's not going to work anyone tell me that how to add color picker in magento 2.1.7



https://webkul.com/blog/add-color-picker-magento2-system-config/










share|improve this question





























    1















    I am trying to add a color picker in magento 2.1.7 using below link but it's not going to work anyone tell me that how to add color picker in magento 2.1.7



    https://webkul.com/blog/add-color-picker-magento2-system-config/










    share|improve this question



























      1












      1








      1








      I am trying to add a color picker in magento 2.1.7 using below link but it's not going to work anyone tell me that how to add color picker in magento 2.1.7



      https://webkul.com/blog/add-color-picker-magento2-system-config/










      share|improve this question
















      I am trying to add a color picker in magento 2.1.7 using below link but it's not going to work anyone tell me that how to add color picker in magento 2.1.7



      https://webkul.com/blog/add-color-picker-magento2-system-config/







      magento2.1.6






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 23 '17 at 12:44









      Teja Bhagavan Kollepara

      2,98641947




      2,98641947










      asked Aug 23 '17 at 9:57









      Sanjay GohilSanjay Gohil

      417113




      417113






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Add JavaScript color picker library in your layout :



          <?xml version="1.0" encoding="UTF-8"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
          <head>
          <css src="jquery/colorpicker/css/colorpicker.css"/>
          </head>
          </page>


          Create system.xml



          <config ...>
          <system>
          ...
          <section>
          ...
          <group id="my_color_group" ...>
          <field id="my_color_option" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
          <label>Background Color</label>
          <comment><![CDATA[Background color]]></comment>
          <frontend_model>abcColorBlockColor</frontend_model> <!-- Our block for attaching color picker to text box -->
          </field>
          </group>
          </section>
          </system>
          </config>


          Create the block file:



          <?php
          namespace abcColorBlock;

          class Color extends MagentoConfigBlockSystemConfigFormField {
          public function __construct(
          MagentoBackendBlockTemplateContext $context, array $data =
          ) {
          parent::__construct($context, $data);
          }

          protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element) {
          $html = $element->getElementHtml();
          $value = $element->getData('value');

          $html .= '<script type="text/javascript">
          require(["jquery","jquery/colorpicker/js/colorpicker"], function ($) {
          $(document).ready(function () {
          var $elementId = $("#' . $element->getHtmlId() . '");
          $elementId.css("backgroundColor", "'. $value .'");

          $elementId.ColorPicker({
          color: "'. $value .'",
          onChange: function (hsb, hex, rgb) {
          $elementId.css("backgroundColor", "#" + hex).val("#" + hex);
          }
          });
          });
          });
          </script>';
          return $html;
          }

          }





          share|improve this answer





















          • 1





            There is no need to add link src="jquery/colorpicker/js/colorpicker.js"/> in layout file...! @Rohan Hapani Thanks...!

            – Sanjay Gohil
            Aug 23 '17 at 13:26













          • ok sir... Happy to helping :)

            – Rohan Hapani
            Aug 23 '17 at 13:46











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f190249%2fhow-to-add-a-color-picker-in-magento-2-1-7-system-config%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Add JavaScript color picker library in your layout :



          <?xml version="1.0" encoding="UTF-8"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
          <head>
          <css src="jquery/colorpicker/css/colorpicker.css"/>
          </head>
          </page>


          Create system.xml



          <config ...>
          <system>
          ...
          <section>
          ...
          <group id="my_color_group" ...>
          <field id="my_color_option" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
          <label>Background Color</label>
          <comment><![CDATA[Background color]]></comment>
          <frontend_model>abcColorBlockColor</frontend_model> <!-- Our block for attaching color picker to text box -->
          </field>
          </group>
          </section>
          </system>
          </config>


          Create the block file:



          <?php
          namespace abcColorBlock;

          class Color extends MagentoConfigBlockSystemConfigFormField {
          public function __construct(
          MagentoBackendBlockTemplateContext $context, array $data =
          ) {
          parent::__construct($context, $data);
          }

          protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element) {
          $html = $element->getElementHtml();
          $value = $element->getData('value');

          $html .= '<script type="text/javascript">
          require(["jquery","jquery/colorpicker/js/colorpicker"], function ($) {
          $(document).ready(function () {
          var $elementId = $("#' . $element->getHtmlId() . '");
          $elementId.css("backgroundColor", "'. $value .'");

          $elementId.ColorPicker({
          color: "'. $value .'",
          onChange: function (hsb, hex, rgb) {
          $elementId.css("backgroundColor", "#" + hex).val("#" + hex);
          }
          });
          });
          });
          </script>';
          return $html;
          }

          }





          share|improve this answer





















          • 1





            There is no need to add link src="jquery/colorpicker/js/colorpicker.js"/> in layout file...! @Rohan Hapani Thanks...!

            – Sanjay Gohil
            Aug 23 '17 at 13:26













          • ok sir... Happy to helping :)

            – Rohan Hapani
            Aug 23 '17 at 13:46
















          3














          Add JavaScript color picker library in your layout :



          <?xml version="1.0" encoding="UTF-8"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
          <head>
          <css src="jquery/colorpicker/css/colorpicker.css"/>
          </head>
          </page>


          Create system.xml



          <config ...>
          <system>
          ...
          <section>
          ...
          <group id="my_color_group" ...>
          <field id="my_color_option" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
          <label>Background Color</label>
          <comment><![CDATA[Background color]]></comment>
          <frontend_model>abcColorBlockColor</frontend_model> <!-- Our block for attaching color picker to text box -->
          </field>
          </group>
          </section>
          </system>
          </config>


          Create the block file:



          <?php
          namespace abcColorBlock;

          class Color extends MagentoConfigBlockSystemConfigFormField {
          public function __construct(
          MagentoBackendBlockTemplateContext $context, array $data =
          ) {
          parent::__construct($context, $data);
          }

          protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element) {
          $html = $element->getElementHtml();
          $value = $element->getData('value');

          $html .= '<script type="text/javascript">
          require(["jquery","jquery/colorpicker/js/colorpicker"], function ($) {
          $(document).ready(function () {
          var $elementId = $("#' . $element->getHtmlId() . '");
          $elementId.css("backgroundColor", "'. $value .'");

          $elementId.ColorPicker({
          color: "'. $value .'",
          onChange: function (hsb, hex, rgb) {
          $elementId.css("backgroundColor", "#" + hex).val("#" + hex);
          }
          });
          });
          });
          </script>';
          return $html;
          }

          }





          share|improve this answer





















          • 1





            There is no need to add link src="jquery/colorpicker/js/colorpicker.js"/> in layout file...! @Rohan Hapani Thanks...!

            – Sanjay Gohil
            Aug 23 '17 at 13:26













          • ok sir... Happy to helping :)

            – Rohan Hapani
            Aug 23 '17 at 13:46














          3












          3








          3







          Add JavaScript color picker library in your layout :



          <?xml version="1.0" encoding="UTF-8"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
          <head>
          <css src="jquery/colorpicker/css/colorpicker.css"/>
          </head>
          </page>


          Create system.xml



          <config ...>
          <system>
          ...
          <section>
          ...
          <group id="my_color_group" ...>
          <field id="my_color_option" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
          <label>Background Color</label>
          <comment><![CDATA[Background color]]></comment>
          <frontend_model>abcColorBlockColor</frontend_model> <!-- Our block for attaching color picker to text box -->
          </field>
          </group>
          </section>
          </system>
          </config>


          Create the block file:



          <?php
          namespace abcColorBlock;

          class Color extends MagentoConfigBlockSystemConfigFormField {
          public function __construct(
          MagentoBackendBlockTemplateContext $context, array $data =
          ) {
          parent::__construct($context, $data);
          }

          protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element) {
          $html = $element->getElementHtml();
          $value = $element->getData('value');

          $html .= '<script type="text/javascript">
          require(["jquery","jquery/colorpicker/js/colorpicker"], function ($) {
          $(document).ready(function () {
          var $elementId = $("#' . $element->getHtmlId() . '");
          $elementId.css("backgroundColor", "'. $value .'");

          $elementId.ColorPicker({
          color: "'. $value .'",
          onChange: function (hsb, hex, rgb) {
          $elementId.css("backgroundColor", "#" + hex).val("#" + hex);
          }
          });
          });
          });
          </script>';
          return $html;
          }

          }





          share|improve this answer















          Add JavaScript color picker library in your layout :



          <?xml version="1.0" encoding="UTF-8"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
          <head>
          <css src="jquery/colorpicker/css/colorpicker.css"/>
          </head>
          </page>


          Create system.xml



          <config ...>
          <system>
          ...
          <section>
          ...
          <group id="my_color_group" ...>
          <field id="my_color_option" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
          <label>Background Color</label>
          <comment><![CDATA[Background color]]></comment>
          <frontend_model>abcColorBlockColor</frontend_model> <!-- Our block for attaching color picker to text box -->
          </field>
          </group>
          </section>
          </system>
          </config>


          Create the block file:



          <?php
          namespace abcColorBlock;

          class Color extends MagentoConfigBlockSystemConfigFormField {
          public function __construct(
          MagentoBackendBlockTemplateContext $context, array $data =
          ) {
          parent::__construct($context, $data);
          }

          protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element) {
          $html = $element->getElementHtml();
          $value = $element->getData('value');

          $html .= '<script type="text/javascript">
          require(["jquery","jquery/colorpicker/js/colorpicker"], function ($) {
          $(document).ready(function () {
          var $elementId = $("#' . $element->getHtmlId() . '");
          $elementId.css("backgroundColor", "'. $value .'");

          $elementId.ColorPicker({
          color: "'. $value .'",
          onChange: function (hsb, hex, rgb) {
          $elementId.css("backgroundColor", "#" + hex).val("#" + hex);
          }
          });
          });
          });
          </script>';
          return $html;
          }

          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 12 mins ago

























          answered Aug 23 '17 at 11:10









          Rohan HapaniRohan Hapani

          6,45331764




          6,45331764








          • 1





            There is no need to add link src="jquery/colorpicker/js/colorpicker.js"/> in layout file...! @Rohan Hapani Thanks...!

            – Sanjay Gohil
            Aug 23 '17 at 13:26













          • ok sir... Happy to helping :)

            – Rohan Hapani
            Aug 23 '17 at 13:46














          • 1





            There is no need to add link src="jquery/colorpicker/js/colorpicker.js"/> in layout file...! @Rohan Hapani Thanks...!

            – Sanjay Gohil
            Aug 23 '17 at 13:26













          • ok sir... Happy to helping :)

            – Rohan Hapani
            Aug 23 '17 at 13:46








          1




          1





          There is no need to add link src="jquery/colorpicker/js/colorpicker.js"/> in layout file...! @Rohan Hapani Thanks...!

          – Sanjay Gohil
          Aug 23 '17 at 13:26







          There is no need to add link src="jquery/colorpicker/js/colorpicker.js"/> in layout file...! @Rohan Hapani Thanks...!

          – Sanjay Gohil
          Aug 23 '17 at 13:26















          ok sir... Happy to helping :)

          – Rohan Hapani
          Aug 23 '17 at 13:46





          ok sir... Happy to helping :)

          – Rohan Hapani
          Aug 23 '17 at 13:46


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f190249%2fhow-to-add-a-color-picker-in-magento-2-1-7-system-config%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What other Star Trek series did the main TNG cast show up in?

          Berlina muro

          Berlina aerponto