How to set default value for text and select field in admin new UI form in magento 2

2018-05-16 01:22:13   Magento

  Magento 2  

How to set default value for text and select field in admin new UI form in magento 2

You need to add below code:

  1. <item name="default" xsi:type="string">1</item>

Example:

  1. <field name="price">
  2. <argument name="data" xsi:type="array">
  3. <item name="config" xsi:type="array">
  4. <item name="label" xsi:type="string" translate="true">Price</item>
  5. <item name="visible" xsi:type="boolean">true</item>
  6. <item name="dataType" xsi:type="string">text</item>
  7. <item name="formElement" xsi:type="string">input</item>
  8. <item name="source" xsi:type="string">product_information</item>
  9. <item name="dataScope" xsi:type="string">price</item>
  10. <item name="default" xsi:type="string">0</item>
  11. <item name="validation" xsi:type="array">
  12. <item name="required-entry" xsi:type="boolean">true</item>
  13. <item name="validate-number" xsi:type="boolean">true</item>
  14. </item>
  15. </item>
  16. </argument>
  17. </field>

Tony's blog image