Magento 2 toggle switch (yes/no) in admin config of custom module using system.xml or in any programmatic way












0















I understand that we can create a toggle switch using form with ui_component. However, I want to create an admin configuration for my custom module using system.xml configuration.




Is there any way to apply the toogle switch (yes/no) (which is a ui_component of magento, to system.xml configuration?
I want it to be implemented instead of a select type with dropdown option.




reference: Magento 2 form field toggled type



enter image description here










share|improve this question





























    0















    I understand that we can create a toggle switch using form with ui_component. However, I want to create an admin configuration for my custom module using system.xml configuration.




    Is there any way to apply the toogle switch (yes/no) (which is a ui_component of magento, to system.xml configuration?
    I want it to be implemented instead of a select type with dropdown option.




    reference: Magento 2 form field toggled type



    enter image description here










    share|improve this question



























      0












      0








      0


      1






      I understand that we can create a toggle switch using form with ui_component. However, I want to create an admin configuration for my custom module using system.xml configuration.




      Is there any way to apply the toogle switch (yes/no) (which is a ui_component of magento, to system.xml configuration?
      I want it to be implemented instead of a select type with dropdown option.




      reference: Magento 2 form field toggled type



      enter image description here










      share|improve this question
















      I understand that we can create a toggle switch using form with ui_component. However, I want to create an admin configuration for my custom module using system.xml configuration.




      Is there any way to apply the toogle switch (yes/no) (which is a ui_component of magento, to system.xml configuration?
      I want it to be implemented instead of a select type with dropdown option.




      reference: Magento 2 form field toggled type



      enter image description here







      magento2 system.xml system-config






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 6 mins ago







      magefms

















      asked Jan 3 at 9:59









      magefmsmagefms

      1,439224




      1,439224






















          2 Answers
          2






          active

          oldest

          votes


















          2














          After several research, I come up with a solution that just provide solution to my requirement. (Not a clean code but still able to come up with the expected results)



          I ended up creating a block to be inserted in the admin system config using the <frontend_model/> markers reference here




          First, I added a Field inside system.xml config gile. It goes like this:




             <field id="status" translate="label" sortOrder="104" showInDefault="1" showInWebsite="0" showInStore="0">
          <frontend_model>VendorModuleBlockAdminhtmlSystemConfigAdvanced</frontend_model>
          <attribute type="shared">1</attribute>
          </field>



          Block file which is the class Advanced code




          <?php

          namespace VendorModuleBlockAdminhtmlSystemConfig;

          class Advanced extends MagentoConfigBlockSystemConfigFormField
          {
          /**
          * Template path
          *
          * @var string
          */
          protected $_template = 'system/config/advance/check.phtml';

          /**
          * Render fieldset html
          *
          * @param MagentoFrameworkDataFormElementAbstractElement $element
          * @return string
          */
          public function render(MagentoFrameworkDataFormElementAbstractElement $element)
          {
          //$columns = $this->getRequest()->getParam('website') || $this->getRequest()->getParam('store') ? 5 : 4;
          return $this->_decorateRowHtml($element, "<td class='label'>Label Text</td><td>" . $this->toHtml() . '</td><td></td>');
          }
          }



          check.phtml code the phtml file




          <style>
          .switch {
          position: relative;
          display: inline-block;
          width: 37px;
          height: 22px;
          vertical-align: middle;

          }

          .switch input {
          opacity: 0;
          width: 0;
          height: 0;
          }

          .slider {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          .slider:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: -7.75px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: .5px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          input:checked + .slider {
          background-color: #79a22e;
          }

          input:focus + .slider {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .sliderOne {
          background-color: #79a22e;
          }

          input:focus + .sliderOne {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .slider:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }
          input:checked + .sliderOne:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }

          /* Rounded sliders */
          .slider.round {
          border-radius: 35px;

          }

          .slider.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          .sliderOne.round {
          border-radius: 35px;

          }

          .sliderOne.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          </style>
          <script>
          function myFunction() {

          if(document.getElementById('spa').classList.contains("slider")) {
          document.getElementsByClassName("slider")[0].setAttribute("class","sliderOne round");
          document.getElementById('toggle').innerHTML = " &nbsp; No";
          }else{
          document.getElementsByClassName("sliderOne")[0].setAttribute("class","slider round");
          document.getElementById('toggle').innerHTML = " &nbsp; Yes";
          }
          }









          Main reference for the whole idea




          The output




          YesNo






          share|improve this answer


























          • Do you spent a lot of hours to obtain that? Why you could not be happy with the dropdown? Are you crazy :) +1 for your determination

            – LucScu
            Jan 23 at 8:54











          • Haha thanks @LucScu

            – magefms
            yesterday





















          0














          You have to use this code in your system.xml



          ...
          <field id="enable_product" translate="label" type="select" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
          <label>Enable Product</label>
          <source_model>MagentoConfigModelConfigSourceYesno</source_model>
          </field>
          ...


          For a full example take a look at system.xml of a mine extension here.






          share|improve this answer


























          • I have updated the question with your answer and inserted the output. kindly check

            – magefms
            Jan 4 at 10:03











          • I need a toggle switch like in the first image.

            – magefms
            Jan 4 at 10:12











          • ok, i understand now...i think is not possible, i don't found anything like you need in the core, every enable settings are with dropdown. Why don't you use a dropdown, but you need a switch?

            – LucScu
            Jan 4 at 14:29











          • a switch is a toggle it is better to use than selecting an option using dropdown.

            – magefms
            Jan 5 at 0:32






          • 1





            okay I'll be posting it.

            – magefms
            Jan 7 at 10:52











          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%2f256587%2fmagento-2-toggle-switch-yes-no-in-admin-config-of-custom-module-using-system-x%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          After several research, I come up with a solution that just provide solution to my requirement. (Not a clean code but still able to come up with the expected results)



          I ended up creating a block to be inserted in the admin system config using the <frontend_model/> markers reference here




          First, I added a Field inside system.xml config gile. It goes like this:




             <field id="status" translate="label" sortOrder="104" showInDefault="1" showInWebsite="0" showInStore="0">
          <frontend_model>VendorModuleBlockAdminhtmlSystemConfigAdvanced</frontend_model>
          <attribute type="shared">1</attribute>
          </field>



          Block file which is the class Advanced code




          <?php

          namespace VendorModuleBlockAdminhtmlSystemConfig;

          class Advanced extends MagentoConfigBlockSystemConfigFormField
          {
          /**
          * Template path
          *
          * @var string
          */
          protected $_template = 'system/config/advance/check.phtml';

          /**
          * Render fieldset html
          *
          * @param MagentoFrameworkDataFormElementAbstractElement $element
          * @return string
          */
          public function render(MagentoFrameworkDataFormElementAbstractElement $element)
          {
          //$columns = $this->getRequest()->getParam('website') || $this->getRequest()->getParam('store') ? 5 : 4;
          return $this->_decorateRowHtml($element, "<td class='label'>Label Text</td><td>" . $this->toHtml() . '</td><td></td>');
          }
          }



          check.phtml code the phtml file




          <style>
          .switch {
          position: relative;
          display: inline-block;
          width: 37px;
          height: 22px;
          vertical-align: middle;

          }

          .switch input {
          opacity: 0;
          width: 0;
          height: 0;
          }

          .slider {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          .slider:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: -7.75px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: .5px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          input:checked + .slider {
          background-color: #79a22e;
          }

          input:focus + .slider {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .sliderOne {
          background-color: #79a22e;
          }

          input:focus + .sliderOne {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .slider:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }
          input:checked + .sliderOne:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }

          /* Rounded sliders */
          .slider.round {
          border-radius: 35px;

          }

          .slider.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          .sliderOne.round {
          border-radius: 35px;

          }

          .sliderOne.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          </style>
          <script>
          function myFunction() {

          if(document.getElementById('spa').classList.contains("slider")) {
          document.getElementsByClassName("slider")[0].setAttribute("class","sliderOne round");
          document.getElementById('toggle').innerHTML = " &nbsp; No";
          }else{
          document.getElementsByClassName("sliderOne")[0].setAttribute("class","slider round");
          document.getElementById('toggle').innerHTML = " &nbsp; Yes";
          }
          }









          Main reference for the whole idea




          The output




          YesNo






          share|improve this answer


























          • Do you spent a lot of hours to obtain that? Why you could not be happy with the dropdown? Are you crazy :) +1 for your determination

            – LucScu
            Jan 23 at 8:54











          • Haha thanks @LucScu

            – magefms
            yesterday


















          2














          After several research, I come up with a solution that just provide solution to my requirement. (Not a clean code but still able to come up with the expected results)



          I ended up creating a block to be inserted in the admin system config using the <frontend_model/> markers reference here




          First, I added a Field inside system.xml config gile. It goes like this:




             <field id="status" translate="label" sortOrder="104" showInDefault="1" showInWebsite="0" showInStore="0">
          <frontend_model>VendorModuleBlockAdminhtmlSystemConfigAdvanced</frontend_model>
          <attribute type="shared">1</attribute>
          </field>



          Block file which is the class Advanced code




          <?php

          namespace VendorModuleBlockAdminhtmlSystemConfig;

          class Advanced extends MagentoConfigBlockSystemConfigFormField
          {
          /**
          * Template path
          *
          * @var string
          */
          protected $_template = 'system/config/advance/check.phtml';

          /**
          * Render fieldset html
          *
          * @param MagentoFrameworkDataFormElementAbstractElement $element
          * @return string
          */
          public function render(MagentoFrameworkDataFormElementAbstractElement $element)
          {
          //$columns = $this->getRequest()->getParam('website') || $this->getRequest()->getParam('store') ? 5 : 4;
          return $this->_decorateRowHtml($element, "<td class='label'>Label Text</td><td>" . $this->toHtml() . '</td><td></td>');
          }
          }



          check.phtml code the phtml file




          <style>
          .switch {
          position: relative;
          display: inline-block;
          width: 37px;
          height: 22px;
          vertical-align: middle;

          }

          .switch input {
          opacity: 0;
          width: 0;
          height: 0;
          }

          .slider {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          .slider:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: -7.75px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: .5px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          input:checked + .slider {
          background-color: #79a22e;
          }

          input:focus + .slider {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .sliderOne {
          background-color: #79a22e;
          }

          input:focus + .sliderOne {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .slider:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }
          input:checked + .sliderOne:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }

          /* Rounded sliders */
          .slider.round {
          border-radius: 35px;

          }

          .slider.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          .sliderOne.round {
          border-radius: 35px;

          }

          .sliderOne.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          </style>
          <script>
          function myFunction() {

          if(document.getElementById('spa').classList.contains("slider")) {
          document.getElementsByClassName("slider")[0].setAttribute("class","sliderOne round");
          document.getElementById('toggle').innerHTML = " &nbsp; No";
          }else{
          document.getElementsByClassName("sliderOne")[0].setAttribute("class","slider round");
          document.getElementById('toggle').innerHTML = " &nbsp; Yes";
          }
          }









          Main reference for the whole idea




          The output




          YesNo






          share|improve this answer


























          • Do you spent a lot of hours to obtain that? Why you could not be happy with the dropdown? Are you crazy :) +1 for your determination

            – LucScu
            Jan 23 at 8:54











          • Haha thanks @LucScu

            – magefms
            yesterday
















          2












          2








          2







          After several research, I come up with a solution that just provide solution to my requirement. (Not a clean code but still able to come up with the expected results)



          I ended up creating a block to be inserted in the admin system config using the <frontend_model/> markers reference here




          First, I added a Field inside system.xml config gile. It goes like this:




             <field id="status" translate="label" sortOrder="104" showInDefault="1" showInWebsite="0" showInStore="0">
          <frontend_model>VendorModuleBlockAdminhtmlSystemConfigAdvanced</frontend_model>
          <attribute type="shared">1</attribute>
          </field>



          Block file which is the class Advanced code




          <?php

          namespace VendorModuleBlockAdminhtmlSystemConfig;

          class Advanced extends MagentoConfigBlockSystemConfigFormField
          {
          /**
          * Template path
          *
          * @var string
          */
          protected $_template = 'system/config/advance/check.phtml';

          /**
          * Render fieldset html
          *
          * @param MagentoFrameworkDataFormElementAbstractElement $element
          * @return string
          */
          public function render(MagentoFrameworkDataFormElementAbstractElement $element)
          {
          //$columns = $this->getRequest()->getParam('website') || $this->getRequest()->getParam('store') ? 5 : 4;
          return $this->_decorateRowHtml($element, "<td class='label'>Label Text</td><td>" . $this->toHtml() . '</td><td></td>');
          }
          }



          check.phtml code the phtml file




          <style>
          .switch {
          position: relative;
          display: inline-block;
          width: 37px;
          height: 22px;
          vertical-align: middle;

          }

          .switch input {
          opacity: 0;
          width: 0;
          height: 0;
          }

          .slider {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          .slider:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: -7.75px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: .5px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          input:checked + .slider {
          background-color: #79a22e;
          }

          input:focus + .slider {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .sliderOne {
          background-color: #79a22e;
          }

          input:focus + .sliderOne {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .slider:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }
          input:checked + .sliderOne:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }

          /* Rounded sliders */
          .slider.round {
          border-radius: 35px;

          }

          .slider.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          .sliderOne.round {
          border-radius: 35px;

          }

          .sliderOne.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          </style>
          <script>
          function myFunction() {

          if(document.getElementById('spa').classList.contains("slider")) {
          document.getElementsByClassName("slider")[0].setAttribute("class","sliderOne round");
          document.getElementById('toggle').innerHTML = " &nbsp; No";
          }else{
          document.getElementsByClassName("sliderOne")[0].setAttribute("class","slider round");
          document.getElementById('toggle').innerHTML = " &nbsp; Yes";
          }
          }









          Main reference for the whole idea




          The output




          YesNo






          share|improve this answer















          After several research, I come up with a solution that just provide solution to my requirement. (Not a clean code but still able to come up with the expected results)



          I ended up creating a block to be inserted in the admin system config using the <frontend_model/> markers reference here




          First, I added a Field inside system.xml config gile. It goes like this:




             <field id="status" translate="label" sortOrder="104" showInDefault="1" showInWebsite="0" showInStore="0">
          <frontend_model>VendorModuleBlockAdminhtmlSystemConfigAdvanced</frontend_model>
          <attribute type="shared">1</attribute>
          </field>



          Block file which is the class Advanced code




          <?php

          namespace VendorModuleBlockAdminhtmlSystemConfig;

          class Advanced extends MagentoConfigBlockSystemConfigFormField
          {
          /**
          * Template path
          *
          * @var string
          */
          protected $_template = 'system/config/advance/check.phtml';

          /**
          * Render fieldset html
          *
          * @param MagentoFrameworkDataFormElementAbstractElement $element
          * @return string
          */
          public function render(MagentoFrameworkDataFormElementAbstractElement $element)
          {
          //$columns = $this->getRequest()->getParam('website') || $this->getRequest()->getParam('store') ? 5 : 4;
          return $this->_decorateRowHtml($element, "<td class='label'>Label Text</td><td>" . $this->toHtml() . '</td><td></td>');
          }
          }



          check.phtml code the phtml file




          <style>
          .switch {
          position: relative;
          display: inline-block;
          width: 37px;
          height: 22px;
          vertical-align: middle;

          }

          .switch input {
          opacity: 0;
          width: 0;
          height: 0;
          }

          .slider {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          .slider:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: -7.75px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }
          .sliderOne:before {
          position: absolute;
          content: "";
          height: 22px;
          width: 22px;
          left: .5px;
          bottom: 0px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
          vertical-align: middle;

          }

          input:checked + .slider {
          background-color: #79a22e;
          }

          input:focus + .slider {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .sliderOne {
          background-color: #79a22e;
          }

          input:focus + .sliderOne {
          box-shadow: 0 0 0px #2196F3;

          }

          input:checked + .slider:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }
          input:checked + .sliderOne:before {
          -webkit-transform: translateX(22px);
          -ms-transform: translateX(22px);
          transform: translateX(22px);

          }

          /* Rounded sliders */
          .slider.round {
          border-radius: 35px;

          }

          .slider.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          .sliderOne.round {
          border-radius: 35px;

          }

          .sliderOne.round:before {
          border-radius: 100%;
          display: inline-block;

          }

          </style>
          <script>
          function myFunction() {

          if(document.getElementById('spa').classList.contains("slider")) {
          document.getElementsByClassName("slider")[0].setAttribute("class","sliderOne round");
          document.getElementById('toggle').innerHTML = " &nbsp; No";
          }else{
          document.getElementsByClassName("sliderOne")[0].setAttribute("class","slider round");
          document.getElementById('toggle').innerHTML = " &nbsp; Yes";
          }
          }









          Main reference for the whole idea




          The output




          YesNo







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 7 at 11:58

























          answered Jan 7 at 11:16









          magefmsmagefms

          1,439224




          1,439224













          • Do you spent a lot of hours to obtain that? Why you could not be happy with the dropdown? Are you crazy :) +1 for your determination

            – LucScu
            Jan 23 at 8:54











          • Haha thanks @LucScu

            – magefms
            yesterday





















          • Do you spent a lot of hours to obtain that? Why you could not be happy with the dropdown? Are you crazy :) +1 for your determination

            – LucScu
            Jan 23 at 8:54











          • Haha thanks @LucScu

            – magefms
            yesterday



















          Do you spent a lot of hours to obtain that? Why you could not be happy with the dropdown? Are you crazy :) +1 for your determination

          – LucScu
          Jan 23 at 8:54





          Do you spent a lot of hours to obtain that? Why you could not be happy with the dropdown? Are you crazy :) +1 for your determination

          – LucScu
          Jan 23 at 8:54













          Haha thanks @LucScu

          – magefms
          yesterday







          Haha thanks @LucScu

          – magefms
          yesterday















          0














          You have to use this code in your system.xml



          ...
          <field id="enable_product" translate="label" type="select" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
          <label>Enable Product</label>
          <source_model>MagentoConfigModelConfigSourceYesno</source_model>
          </field>
          ...


          For a full example take a look at system.xml of a mine extension here.






          share|improve this answer


























          • I have updated the question with your answer and inserted the output. kindly check

            – magefms
            Jan 4 at 10:03











          • I need a toggle switch like in the first image.

            – magefms
            Jan 4 at 10:12











          • ok, i understand now...i think is not possible, i don't found anything like you need in the core, every enable settings are with dropdown. Why don't you use a dropdown, but you need a switch?

            – LucScu
            Jan 4 at 14:29











          • a switch is a toggle it is better to use than selecting an option using dropdown.

            – magefms
            Jan 5 at 0:32






          • 1





            okay I'll be posting it.

            – magefms
            Jan 7 at 10:52
















          0














          You have to use this code in your system.xml



          ...
          <field id="enable_product" translate="label" type="select" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
          <label>Enable Product</label>
          <source_model>MagentoConfigModelConfigSourceYesno</source_model>
          </field>
          ...


          For a full example take a look at system.xml of a mine extension here.






          share|improve this answer


























          • I have updated the question with your answer and inserted the output. kindly check

            – magefms
            Jan 4 at 10:03











          • I need a toggle switch like in the first image.

            – magefms
            Jan 4 at 10:12











          • ok, i understand now...i think is not possible, i don't found anything like you need in the core, every enable settings are with dropdown. Why don't you use a dropdown, but you need a switch?

            – LucScu
            Jan 4 at 14:29











          • a switch is a toggle it is better to use than selecting an option using dropdown.

            – magefms
            Jan 5 at 0:32






          • 1





            okay I'll be posting it.

            – magefms
            Jan 7 at 10:52














          0












          0








          0







          You have to use this code in your system.xml



          ...
          <field id="enable_product" translate="label" type="select" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
          <label>Enable Product</label>
          <source_model>MagentoConfigModelConfigSourceYesno</source_model>
          </field>
          ...


          For a full example take a look at system.xml of a mine extension here.






          share|improve this answer















          You have to use this code in your system.xml



          ...
          <field id="enable_product" translate="label" type="select" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
          <label>Enable Product</label>
          <source_model>MagentoConfigModelConfigSourceYesno</source_model>
          </field>
          ...


          For a full example take a look at system.xml of a mine extension here.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 4 at 9:59

























          answered Jan 4 at 9:52









          LucScuLucScu

          1,2811130




          1,2811130













          • I have updated the question with your answer and inserted the output. kindly check

            – magefms
            Jan 4 at 10:03











          • I need a toggle switch like in the first image.

            – magefms
            Jan 4 at 10:12











          • ok, i understand now...i think is not possible, i don't found anything like you need in the core, every enable settings are with dropdown. Why don't you use a dropdown, but you need a switch?

            – LucScu
            Jan 4 at 14:29











          • a switch is a toggle it is better to use than selecting an option using dropdown.

            – magefms
            Jan 5 at 0:32






          • 1





            okay I'll be posting it.

            – magefms
            Jan 7 at 10:52



















          • I have updated the question with your answer and inserted the output. kindly check

            – magefms
            Jan 4 at 10:03











          • I need a toggle switch like in the first image.

            – magefms
            Jan 4 at 10:12











          • ok, i understand now...i think is not possible, i don't found anything like you need in the core, every enable settings are with dropdown. Why don't you use a dropdown, but you need a switch?

            – LucScu
            Jan 4 at 14:29











          • a switch is a toggle it is better to use than selecting an option using dropdown.

            – magefms
            Jan 5 at 0:32






          • 1





            okay I'll be posting it.

            – magefms
            Jan 7 at 10:52

















          I have updated the question with your answer and inserted the output. kindly check

          – magefms
          Jan 4 at 10:03





          I have updated the question with your answer and inserted the output. kindly check

          – magefms
          Jan 4 at 10:03













          I need a toggle switch like in the first image.

          – magefms
          Jan 4 at 10:12





          I need a toggle switch like in the first image.

          – magefms
          Jan 4 at 10:12













          ok, i understand now...i think is not possible, i don't found anything like you need in the core, every enable settings are with dropdown. Why don't you use a dropdown, but you need a switch?

          – LucScu
          Jan 4 at 14:29





          ok, i understand now...i think is not possible, i don't found anything like you need in the core, every enable settings are with dropdown. Why don't you use a dropdown, but you need a switch?

          – LucScu
          Jan 4 at 14:29













          a switch is a toggle it is better to use than selecting an option using dropdown.

          – magefms
          Jan 5 at 0:32





          a switch is a toggle it is better to use than selecting an option using dropdown.

          – magefms
          Jan 5 at 0:32




          1




          1





          okay I'll be posting it.

          – magefms
          Jan 7 at 10:52





          okay I'll be posting it.

          – magefms
          Jan 7 at 10:52


















          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%2f256587%2fmagento-2-toggle-switch-yes-no-in-admin-config-of-custom-module-using-system-x%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