I have created a Custom Module using the UI Component on Admin Side. Now i Need to show a Current Currency symbol or currency code in this field like above image
1 Answer
You can display a static value by adding the line below to your form field:
<item name="addbefore" xsi:type="string">$</item> Sample Code
<field name="price_custom_att" > <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="dataType" xsi:type="string">text</item> <item name="label" xsi:type="string" translate="true">Custom Price Attribute</item> <item name="formElement" xsi:type="string">input</item> <item name="source" xsi:type="string">price_custom_att</item> <item name="dataScope" xsi:type="string">price_custom_att</item> <item name="default" xsi:type="string">1</item> <item name="addbefore" xsi:type="string">$</item> </item> </argument> </field> If you want a dynamic value based on attributes like the default price attribute, you need to convert your attribute type to 'price.' If you do not want to convert, then you need to update the metadata of the form, as shown in the file below.
File : vendor/magento/module-catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php
/** * Customize attribute that has price type * * @param ProductAttributeInterface $attribute * @param array $meta * @return array */ private function customizePriceAttribute(ProductAttributeInterface $attribute, array $meta) { if ($attribute->getFrontendInput() === 'price') { $meta['arguments']['data']['config']['addbefore'] = $this->locator->getStore() ->getBaseCurrency() ->getCurrencySymbol(); } return $meta; } Update custom form metadata. Check this link: https://magento.stackexchange.com/a/370154/82670
