0

I am creating a multi-select category field for admin side using ui-component my code for ui-component is

 <field name="category_id">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Magento\Catalog\Ui\Component\Product\Form\Categories\Options</item>
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Category</item>
                <item name="componentType" xsi:type="string">field</item>
                <item name="formElement" xsi:type="string">select</item>
                <item name="component" xsi:type="string">Magento_Catalog/js/components/new-category</item>
                <item name="elementTmpl" xsi:type="string">ui/grid/filters/elements/ui-select</item>
                <item name="dataScope" xsi:type="string">category_id</item>
                <item name="filterOptions" xsi:type="boolean">true</item>
                <item name="showCheckbox" xsi:type="boolean">true</item>
                <item name="disableLabel" xsi:type="boolean">true</item>
                <item name="multiple" xsi:type="boolean">true</item>
                <item name="levelsVisibility" xsi:type="number">1</item>
                <item name="sortOrder" xsi:type="number">30</item>
                <item name="required" xsi:type="boolean">true</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>
                </item>
                <item name="listens" xsi:type="array">
                    <item name="${ $.namespace }.${ $.namespace }:responseData" xsi:type="string">setParsed</item>
                </item>
            </item>
        </argument>
    </field>

The Code is working fine but it returns too many commas and 1 repeated e.g if i select pants and shots it still returns 1 with it

[category_id] => Array
        (
            [0] => 1
            [1] => ,
            [2] => ,
            [3] => ,
            [4] => ,
            [5] => ,
            [6] => ,
            [7] => ,
            [8] => ,
            [9] => ,
            [10] => ,
            [11] => ,
            [12] => ,
            [13] => ,
            [14] => ,
            [15] => ,
            [16] => ,
            [17] => ,
            [18] => ,
            [19] => ,
            [20] => ,
            [21] => ,
            [22] => ,
            [23] => ,
            [24] => ,
            [25] => ,
            [26] => ,
            [27] => ,
            [28] => ,
            [29] => ,
            [30] => ,
            [31] => ,
            [32] => 1
            [33] => ,
            [34] => ,
            [35] => ,
            [36] => ,
            [37] => ,
            [38] => ,
            [39] => ,
            [40] => ,
            [41] => ,
            [42] => ,
            [43] => ,
            [44] => ,
            [45] => ,
            [46] => ,
            [47] => ,
            [48] => ,
            [49] => ,
            [50] => ,
            [51] => ,
            [52] => ,
            [53] => ,
            [54] => ,
            [55] => ,
            [56] => ,
            [57] => ,
            [58] => ,
            [59] => ,
            [60] => ,
            [61] => ,
            [62] => ,
            [63] => ,
            [64] => ,
            [65] => ,
            [66] => ,
            [67] => ,
            [68] => ,
            [69] => ,
            [70] => ,
            [71] => ,
            [72] => ,
            [73] => ,
            [74] => ,
            [75] => ,
            [76] => ,
            [77] => ,
            [78] => ,
            [79] => ,
            [80] => ,
            [81] => ,
            [82] => ,
            [83] => ,
            [84] => ,
            [85] => ,
            [86] => ,
            [87] => ,
            [88] => ,
            [89] => ,
            [90] => ,
            [91] => ,
            [92] => ,
            [93] => ,
            [94] => ,
            [95] => ,
            [96] => 1
            [97] => ,
            [98] => ,
            [99] => ,
            [100] => ,
            [101] => ,
            [102] => ,
            [103] => ,
            [104] => ,
            [105] => ,
            [106] => ,
            [107] => ,
            [108] => ,
            [109] => ,
            [110] => ,
            [111] => ,
            [112] => ,
            [113] => ,
            [114] => ,
            [115] => ,
            [116] => ,
            [117] => ,
            [118] => ,
            [119] => ,
            [120] => ,
            [121] => ,
            [122] => ,
            [123] => ,
            [124] => ,
            [125] => ,
            [126] => ,
            [127] => ,
            [128] => 1
            [129] => ,
            [130] => ,
            [131] => ,
            [132] => ,
            [133] => ,
            [134] => ,
            [135] => ,
            [136] => ,
            [137] => ,
            [138] => ,
            [139] => ,
            [140] => ,
            [141] => ,
            [142] => ,
            [143] => ,
            [144] => 1
            [145] => ,
            [146] => ,
            [147] => ,
            [148] => 1
            [149] => ,
            [150] => 1
            [151] => 18
            [152] => 19
        )

I only want to add the selected categories and want to get rid of commas and 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.