2

I have added some custom fields to my product edit page and it is working now. But I want to show the saved values in the edit. Now i am able to show the values in text fields. but i don't know how to do the same in toggle box.

my xml for toggle box

       <field name="price_on_request">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">4000</item>
                    <item name="dataType" xsi:type="string">boolean</item>
                    <item name="formElement" xsi:type="string">checkbox</item>
                    <item name="source" xsi:type="string">category</item>
                    <item name="prefer" xsi:type="string">toggle</item>
                    <item name="label" xsi:type="string" translate="true">Price on request</item>
                    <item name="notice" xsi:type="string">Price will not be displayed.</item>
                    <item name="valueMap" xsi:type="array">
                        <item name="true" xsi:type="string">1</item>
                        <item name="false" xsi:type="string">0</item>
                    </item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">false</item>
                    </item>
                    <item name="default" xsi:type="string">0</item>
                </item>
            </argument>
        </field>

now i am using this method to set values when edit

 public function afterModifyData(
    \Magento\CatalogInventory\Ui\DataProvider\Product\Form\Modifier\AdvancedInventory $subject,
    $data
) {
    $productId = $data['1']['product']['stock_data']['product_id'];
    $data[strval($productId)]['magenest']['price_on_request'] = 1;
    $data[strval($productId)]['magenest']['surcharge'] = 40;

    return $data;
}

now i can able to see the surcharge value is displaying fine, but toggle box is not showing as true/checked.

how can i manipulate the toggle box like here? please help me.

1

Thanks all I got my solution now.

Just changed int to string is solved for me.

  `$data[strval($productId)]['magenest']['price_on_request'] = '1';`

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.