Magento 2 How to get category tree with checkbox to select only one category?How to load category tree with category imageuiComponent Form. How to show data from DB tableMagento 2 :- Add select attribute to categoryMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formMagento offline custom Payment method with drop down listHow to solve Front controller reached 100 router match iterations in magento2I have created one field using product form field for my price i want save my field value at product creation time from backend magento2Load category, but only with limited data to build a BreadcrumbHow to create custom form in Magento 2.2.3

When is pointing out a person's hypocrisy not considered to be a logical fallacy?

Find values of x so that the matrix is invertible

Why does the autopilot disengage even when it does not receive pilot input?

Does Google Maps take into account hills/inclines for route times?

How does one stock fund's charge of 1% more in operating expenses than another fund lower expected returns by 10%?

TikZ Can I draw an arrow by specifying the initial point, direction, and length?

Missing Contours in ContourPlot

Should you avoid redundant information after dialogue?

How many matrices satisfy this equality?

Did any of the founding fathers anticipate Lysander Spooner's criticism of the constitution?

Where is my understanding of TikZ styles wrong?

How can an advanced civilization forget how to manufacture its technology?

How can one write good dialogue in a story without sounding wooden?

Find the wrong number in the given series: 6, 12, 21, 36, 56, 81?

Professor falsely accusing me of cheating in a class he does not teach, two months after end of the class. What precautions should I take?

Extract an attribute value from XML

Why is dry soil hydrophobic? Bad gardener paradox

Why did the Japanese attack the Aleutians at the same time as Midway?

Optimising Table wrapping over a Select

QGIS Linestring rendering curves between vertex

wavelength of seismic wave with a gaussian source

What would the EU do if an EU member declared war on another EU member?

How can I deal with a player trying to insert real-world mythology into my homebrew setting?

Occasus nescius



Magento 2 How to get category tree with checkbox to select only one category?


How to load category tree with category imageuiComponent Form. How to show data from DB tableMagento 2 :- Add select attribute to categoryMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formMagento offline custom Payment method with drop down listHow to solve Front controller reached 100 router match iterations in magento2I have created one field using product form field for my price i want save my field value at product creation time from backend magento2Load category, but only with limited data to build a BreadcrumbHow to create custom form in Magento 2.2.3






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to call the categories into my custom admin form for admin. How can I call that?



enter image description here



I want to show all categories into my custom form in admin and it will allow selecting only one category.



I used the below code but it is showing nothing in my form what is wrong here?



<referenceContainer name="content">
<block class="NameModuleBlockAdminhtmlCategoryDuplicateFormCategories" name="name.dupcat.categorydropdown">
<uiComponent name="categories_form"/>
</block>
</referenceContainer>


-- view/adminhtml/ui_component/categories_form.xml



<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general">
<field name="categories" component="Name/Module/js/select-category" sortOrder="20" formElement="select" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filterOptions" xsi:type="boolean">true</item>
<item name="multiple" xsi:type="boolean">false</item>
<item name="showCheckbox" xsi:type="boolean">true</item>
<item name="disableLabel" xsi:type="boolean">true</item>
</item>
</argument>
<settings>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
</validation>
<elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
<label translate="true">Select Category</label>
<dataScope>categories</dataScope>
<componentType>field</componentType>
<listens>
<link name="$ $.nametdupcat .$ $.nametdupcat :responseData">setParsed</link>
</listens>
</settings>
<formElements>
<select>
<settings>
<options class="NameModuleUiComponentFormCategoryOptions"/>
</settings>
</select>
</formElements>
</field>
</fieldset>
</form>


-- UiComponentFormCategoryOptions.php



<?php
namespace NameModuleUiComponentFormCategory;

use MagentoFrameworkDataOptionSourceInterface;
use MagentoCatalogModelResourceModelCategoryCollectionFactory as CategoryCollectionFactory;
use MagentoFrameworkAppRequestInterface;

class Options implements OptionSourceInterface

protected $categoryCollectionFactory;
protected $request;
protected $categoryTree;

public function __construct(
CategoryCollectionFactory $categoryCollectionFactory,
RequestInterface $request
)
$this->categoryCollectionFactory = $categoryCollectionFactory;
$this->request = $request;


public function toOptionArray()

return $this->getCategoryTree();


protected function getCategoryTree()

if ($this->categoryTree === null)
$collection = $this->categoryCollectionFactory->create();

$collection->addAttributeToSelect('name');

foreach ($collection as $category)
$categoryId = $category->getEntityId();
if (!isset($categoryById[$categoryId]))
$categoryById[$categoryId] = [
'value' => $categoryId
];

$categoryById[$categoryId]['label'] = $category->getName();

$this->categoryTree = $categoryById;

return $this->categoryTree;




-- viewadminhtmlwebjsselect-category.js



define([
'Magento_Ui/js/form/element/ui-select'
], function (Select)
'use strict';
return Select.extend(
setParsed: function (data)
var option = this.parseData(data);
if (data.error)
return this;

this.options([]);
this.setOption(option);
this.set('newOption', option);
,

parseData: function (data)
return
value: data.category.entity_id,
label: data.category.name
;

);
);









share|improve this question




























    0















    I want to call the categories into my custom admin form for admin. How can I call that?



    enter image description here



    I want to show all categories into my custom form in admin and it will allow selecting only one category.



    I used the below code but it is showing nothing in my form what is wrong here?



    <referenceContainer name="content">
    <block class="NameModuleBlockAdminhtmlCategoryDuplicateFormCategories" name="name.dupcat.categorydropdown">
    <uiComponent name="categories_form"/>
    </block>
    </referenceContainer>


    -- view/adminhtml/ui_component/categories_form.xml



    <?xml version="1.0" encoding="UTF-8"?>
    <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="general">
    <field name="categories" component="Name/Module/js/select-category" sortOrder="20" formElement="select" >
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="filterOptions" xsi:type="boolean">true</item>
    <item name="multiple" xsi:type="boolean">false</item>
    <item name="showCheckbox" xsi:type="boolean">true</item>
    <item name="disableLabel" xsi:type="boolean">true</item>
    </item>
    </argument>
    <settings>
    <validation>
    <rule name="required-entry" xsi:type="boolean">true</rule>
    </validation>
    <elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
    <label translate="true">Select Category</label>
    <dataScope>categories</dataScope>
    <componentType>field</componentType>
    <listens>
    <link name="$ $.nametdupcat .$ $.nametdupcat :responseData">setParsed</link>
    </listens>
    </settings>
    <formElements>
    <select>
    <settings>
    <options class="NameModuleUiComponentFormCategoryOptions"/>
    </settings>
    </select>
    </formElements>
    </field>
    </fieldset>
    </form>


    -- UiComponentFormCategoryOptions.php



    <?php
    namespace NameModuleUiComponentFormCategory;

    use MagentoFrameworkDataOptionSourceInterface;
    use MagentoCatalogModelResourceModelCategoryCollectionFactory as CategoryCollectionFactory;
    use MagentoFrameworkAppRequestInterface;

    class Options implements OptionSourceInterface

    protected $categoryCollectionFactory;
    protected $request;
    protected $categoryTree;

    public function __construct(
    CategoryCollectionFactory $categoryCollectionFactory,
    RequestInterface $request
    )
    $this->categoryCollectionFactory = $categoryCollectionFactory;
    $this->request = $request;


    public function toOptionArray()

    return $this->getCategoryTree();


    protected function getCategoryTree()

    if ($this->categoryTree === null)
    $collection = $this->categoryCollectionFactory->create();

    $collection->addAttributeToSelect('name');

    foreach ($collection as $category)
    $categoryId = $category->getEntityId();
    if (!isset($categoryById[$categoryId]))
    $categoryById[$categoryId] = [
    'value' => $categoryId
    ];

    $categoryById[$categoryId]['label'] = $category->getName();

    $this->categoryTree = $categoryById;

    return $this->categoryTree;




    -- viewadminhtmlwebjsselect-category.js



    define([
    'Magento_Ui/js/form/element/ui-select'
    ], function (Select)
    'use strict';
    return Select.extend(
    setParsed: function (data)
    var option = this.parseData(data);
    if (data.error)
    return this;

    this.options([]);
    this.setOption(option);
    this.set('newOption', option);
    ,

    parseData: function (data)
    return
    value: data.category.entity_id,
    label: data.category.name
    ;

    );
    );









    share|improve this question
























      0












      0








      0








      I want to call the categories into my custom admin form for admin. How can I call that?



      enter image description here



      I want to show all categories into my custom form in admin and it will allow selecting only one category.



      I used the below code but it is showing nothing in my form what is wrong here?



      <referenceContainer name="content">
      <block class="NameModuleBlockAdminhtmlCategoryDuplicateFormCategories" name="name.dupcat.categorydropdown">
      <uiComponent name="categories_form"/>
      </block>
      </referenceContainer>


      -- view/adminhtml/ui_component/categories_form.xml



      <?xml version="1.0" encoding="UTF-8"?>
      <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
      <fieldset name="general">
      <field name="categories" component="Name/Module/js/select-category" sortOrder="20" formElement="select" >
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="filterOptions" xsi:type="boolean">true</item>
      <item name="multiple" xsi:type="boolean">false</item>
      <item name="showCheckbox" xsi:type="boolean">true</item>
      <item name="disableLabel" xsi:type="boolean">true</item>
      </item>
      </argument>
      <settings>
      <validation>
      <rule name="required-entry" xsi:type="boolean">true</rule>
      </validation>
      <elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
      <label translate="true">Select Category</label>
      <dataScope>categories</dataScope>
      <componentType>field</componentType>
      <listens>
      <link name="$ $.nametdupcat .$ $.nametdupcat :responseData">setParsed</link>
      </listens>
      </settings>
      <formElements>
      <select>
      <settings>
      <options class="NameModuleUiComponentFormCategoryOptions"/>
      </settings>
      </select>
      </formElements>
      </field>
      </fieldset>
      </form>


      -- UiComponentFormCategoryOptions.php



      <?php
      namespace NameModuleUiComponentFormCategory;

      use MagentoFrameworkDataOptionSourceInterface;
      use MagentoCatalogModelResourceModelCategoryCollectionFactory as CategoryCollectionFactory;
      use MagentoFrameworkAppRequestInterface;

      class Options implements OptionSourceInterface

      protected $categoryCollectionFactory;
      protected $request;
      protected $categoryTree;

      public function __construct(
      CategoryCollectionFactory $categoryCollectionFactory,
      RequestInterface $request
      )
      $this->categoryCollectionFactory = $categoryCollectionFactory;
      $this->request = $request;


      public function toOptionArray()

      return $this->getCategoryTree();


      protected function getCategoryTree()

      if ($this->categoryTree === null)
      $collection = $this->categoryCollectionFactory->create();

      $collection->addAttributeToSelect('name');

      foreach ($collection as $category)
      $categoryId = $category->getEntityId();
      if (!isset($categoryById[$categoryId]))
      $categoryById[$categoryId] = [
      'value' => $categoryId
      ];

      $categoryById[$categoryId]['label'] = $category->getName();

      $this->categoryTree = $categoryById;

      return $this->categoryTree;




      -- viewadminhtmlwebjsselect-category.js



      define([
      'Magento_Ui/js/form/element/ui-select'
      ], function (Select)
      'use strict';
      return Select.extend(
      setParsed: function (data)
      var option = this.parseData(data);
      if (data.error)
      return this;

      this.options([]);
      this.setOption(option);
      this.set('newOption', option);
      ,

      parseData: function (data)
      return
      value: data.category.entity_id,
      label: data.category.name
      ;

      );
      );









      share|improve this question














      I want to call the categories into my custom admin form for admin. How can I call that?



      enter image description here



      I want to show all categories into my custom form in admin and it will allow selecting only one category.



      I used the below code but it is showing nothing in my form what is wrong here?



      <referenceContainer name="content">
      <block class="NameModuleBlockAdminhtmlCategoryDuplicateFormCategories" name="name.dupcat.categorydropdown">
      <uiComponent name="categories_form"/>
      </block>
      </referenceContainer>


      -- view/adminhtml/ui_component/categories_form.xml



      <?xml version="1.0" encoding="UTF-8"?>
      <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
      <fieldset name="general">
      <field name="categories" component="Name/Module/js/select-category" sortOrder="20" formElement="select" >
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="filterOptions" xsi:type="boolean">true</item>
      <item name="multiple" xsi:type="boolean">false</item>
      <item name="showCheckbox" xsi:type="boolean">true</item>
      <item name="disableLabel" xsi:type="boolean">true</item>
      </item>
      </argument>
      <settings>
      <validation>
      <rule name="required-entry" xsi:type="boolean">true</rule>
      </validation>
      <elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
      <label translate="true">Select Category</label>
      <dataScope>categories</dataScope>
      <componentType>field</componentType>
      <listens>
      <link name="$ $.nametdupcat .$ $.nametdupcat :responseData">setParsed</link>
      </listens>
      </settings>
      <formElements>
      <select>
      <settings>
      <options class="NameModuleUiComponentFormCategoryOptions"/>
      </settings>
      </select>
      </formElements>
      </field>
      </fieldset>
      </form>


      -- UiComponentFormCategoryOptions.php



      <?php
      namespace NameModuleUiComponentFormCategory;

      use MagentoFrameworkDataOptionSourceInterface;
      use MagentoCatalogModelResourceModelCategoryCollectionFactory as CategoryCollectionFactory;
      use MagentoFrameworkAppRequestInterface;

      class Options implements OptionSourceInterface

      protected $categoryCollectionFactory;
      protected $request;
      protected $categoryTree;

      public function __construct(
      CategoryCollectionFactory $categoryCollectionFactory,
      RequestInterface $request
      )
      $this->categoryCollectionFactory = $categoryCollectionFactory;
      $this->request = $request;


      public function toOptionArray()

      return $this->getCategoryTree();


      protected function getCategoryTree()

      if ($this->categoryTree === null)
      $collection = $this->categoryCollectionFactory->create();

      $collection->addAttributeToSelect('name');

      foreach ($collection as $category)
      $categoryId = $category->getEntityId();
      if (!isset($categoryById[$categoryId]))
      $categoryById[$categoryId] = [
      'value' => $categoryId
      ];

      $categoryById[$categoryId]['label'] = $category->getName();

      $this->categoryTree = $categoryById;

      return $this->categoryTree;




      -- viewadminhtmlwebjsselect-category.js



      define([
      'Magento_Ui/js/form/element/ui-select'
      ], function (Select)
      'use strict';
      return Select.extend(
      setParsed: function (data)
      var option = this.parseData(data);
      if (data.error)
      return this;

      this.options([]);
      this.setOption(option);
      this.set('newOption', option);
      ,

      parseData: function (data)
      return
      value: data.category.entity_id,
      label: data.category.name
      ;

      );
      );






      magento2 module admin category






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 5 at 11:06









      Utsav GuptaUtsav Gupta

      4972 silver badges16 bronze badges




      4972 silver badges16 bronze badges




















          0






          active

          oldest

          votes














          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%2f280958%2fmagento-2-how-to-get-category-tree-with-checkbox-to-select-only-one-category%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f280958%2fmagento-2-how-to-get-category-tree-with-checkbox-to-select-only-one-category%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

          Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

          Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

          Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림