Is there a right way pass data (request value) to form ui-component?
I have try to setData from DataProvider define in form-ui.xml but not work. After form load complete this field must be populated data (initial value)
/**
* Get data from provider and populate
* @param void
* @return array
*/
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
if ($itemId)
$items = $this->collection->getItems();
$data = $this->dataPersistor->get('form_item');
if (!empty($data)) {
//Do something
} else {
//When form init without any data
// I want to setData for some field here
}
return $this->loadedData;
}
My current question:
1 – How to setData in the right way for ui way? If my way not right is there a better way to do setdata for field
2 – Side question: How core-team can make magento find exactly which form to interactive. In old way form , we can define form original with form tag, htmlIdPrefix … etc But in new form i can't find anywhere in uiform.xml to configuration id form, form prefix .. I am curious how it work
It will be great if know about it
Best Answer
In your custom_form.xml file
Where you can set select dynamic option from this class,
{Vendorname}\{Modulename}\Model\Classname
using toOptionArray() method.In DataProvider.php file,
Another way to get data Using UI component.
If you want get dafault value from another module using UI component
Add this field in your custom_form.xml file
In DataProvider.php file,