I want to set a form field value from the URL params in UI form. I am aware that static values can be set via default
property of the field
but how to set dynamic values as default (to be specific request URL params).
Also, what is the standard way to do it?
`http://localhost/magento/2.2.4/admin/mymodule/myform/edit/type/vendor/`
Here, type/vendor
the value vendor needs to be set on type
field as default
.
<field name="type">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">MyModule\MyVendor\Model\Source\Type</item>
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">true</item>
<item name="dataType" xsi:type="string">select</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">mymodule_myform_form_data_source</item>
<item name="label" xsi:type="string" translate="true">Type</item>
<item name="disabled" xsi:type="boolean">true</item>
<item name="default" xsi:type="string">inventory</item>
</item>
</argument>
</field>
MyModule\MyVendor\Model\Source\Type.php
<?php
namespace MyModule\MyVendor\Model\Source;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
class Type extends AbstractSource
{
/**
* @return array
*/
public function getAllOptions()
{
return [
[
'value' => 'vendor',
'label' => __('Vendor'),
],
];
}
}
MyModule\MyVendor\Model\Source\Type
codesid
for it.