3

I want to add an image field of UI component on traditional block form.

I want to replace only this field with UI component. The reset field should be in Block class form.

$fieldset->addField(
        'outfit_image',
        'image',
        [
            'name' => 'outfit_image',
            'label' => __('Outfit Image'),
            'title' => __('Outfit Image'),
            'required' => true,
            'data-form-part' => $this->getData('target_form'),
            'note' => __('Maximum file size: 2 MB.'),
        ]
    );

With This

<field name="outfit_image">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">string</item>
                <item name="source" xsi:type="string">Outfit Image</item>
                <item name="label" xsi:type="string" translate="true">Image</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="formElement" xsi:type="string">imageUploader</item>
                <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
                <item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>
                <item name="uploaderConfig" xsi:type="array">
                    <item name="url" xsi:type="url" path="outfit/image/upload"/>
                </item>
            </item>
        </argument>
    </field>

1 Answer 1

0

You can try with fileUploader

<field name="outfit_image">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="source" xsi:type="string">source</item>
                    <item name="label" xsi:type="string" translate="true">Outfit Image</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="formElement" xsi:type="string">fileUploader</item>
                    <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
                    <item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item>
                    <item name="required" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="number">40</item>
                    <item name="uploaderConfig" xsi:type="array">
                        <item name="url" xsi:type="url" path="outfit/image/upload"/>
                    </item>
                </item>
            </argument>
        </field>
6
  • Ya but how can i put this in block class. That's my question.
    – Avesh Naik
    Commented May 10, 2019 at 6:09
  • Saving thing i know. I want to add the UI field(XML thing) in Block form Class (PHP thing)
    – Avesh Naik
    Commented May 10, 2019 at 6:28
  • 1
    got it to let me check on it Commented May 10, 2019 at 6:29
  • 1
    Please check this answer magento.stackexchange.com/questions/151685/… Commented May 10, 2019 at 6:39
  • 1
    Not what i was looking for.
    – Avesh Naik
    Commented May 10, 2019 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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