How Do we can give dynamic data for a form field in admin form(ui-component) in magento 2Product Listing Ui...

Why does processed meat contain preservatives, while canned fish needs not?

French for 'It must be my imagination'?

Please, smoke with good manners

How to get a plain text file version of a CP/M .BAS (M-BASIC) program?

Why do Computer Science majors learn Calculus?

How to have a sharp product image?

Controversial area of mathematics

What are the potential pitfalls when using metals as a currency?

Phrase for the opposite of "foolproof"

Why is it that the natural deduction method can't test for invalidity?

What language was spoken in East Asia before Proto-Turkic?

Exchange,swap or switch

Rivers without rain

Do I have an "anti-research" personality?

Is there really no use for MD5 anymore?

How can I practically buy stocks?

Can someone publish a story that happened to you?

To say I met a person for the first time

What's the polite way to say "I need to urinate"?

How to verbalise code in Mathematica?

Size of electromagnet needed to replicate Earth's magnetic field

How can I place the product on a social media post better?

Don’t seats that recline flat defeat the purpose of having seatbelts?

Document starts having heaps of errors in the middle, but the code doesn't have any problems in it



How Do we can give dynamic data for a form field in admin form(ui-component) in magento 2


Product Listing Ui Component xml file not overriding in custom moduleMagento 2 Admin Form FieldMagento 2 Add new field to Magento_User admin formCan't set value for wysiwyg field component in admin formMagento2: Dependency in admin form fieldHow to add default values for system configuration in magento 2Add a generic field in admin formHow to Update Magento 2 configurable child products price by REST APIField labels missing from UI component formHow to create dynamic rows field in custom Ui component formHow to add form element CANVAS using ui component magento admin form






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I need to add note to the form field using notice tag. for example



 <notice translate="true">Image size should be equal to some(here I
need to pass dynamic value)</notice>


form.xml



 <field name="image" sortOrder="60" formElement="fileUploader">
<settings>
<notice translate="true">Image size should be equal to some(here I need to pass dynamic value)</notice>
<label translate="true">Image</label>
<componentType>fileUploader</componentType>
<visible>true</visible>
</settings>
<formElements>
<fileUploader>
<settings>
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
<maxFileSize>102400</maxFileSize>
<uploaderConfig>
<param xsi:type="string" name="url">a/b/c</param>
</uploaderConfig>
<previewTmpl>x_y/image-preview</previewTmpl>
</settings>
</fileUploader>
</formElements>
</field>









share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • how to create form using ui-component? or simple

    – Birjitsinh Zala
    Jan 17 '18 at 13:11











  • I have created form using ui-component

    – Jaisa
    Jan 17 '18 at 13:12













  • <uiComponent name="vendor_department_addform"/> wait am write full code in ans

    – Birjitsinh Zala
    Jan 17 '18 at 13:15


















0















I need to add note to the form field using notice tag. for example



 <notice translate="true">Image size should be equal to some(here I
need to pass dynamic value)</notice>


form.xml



 <field name="image" sortOrder="60" formElement="fileUploader">
<settings>
<notice translate="true">Image size should be equal to some(here I need to pass dynamic value)</notice>
<label translate="true">Image</label>
<componentType>fileUploader</componentType>
<visible>true</visible>
</settings>
<formElements>
<fileUploader>
<settings>
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
<maxFileSize>102400</maxFileSize>
<uploaderConfig>
<param xsi:type="string" name="url">a/b/c</param>
</uploaderConfig>
<previewTmpl>x_y/image-preview</previewTmpl>
</settings>
</fileUploader>
</formElements>
</field>









share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • how to create form using ui-component? or simple

    – Birjitsinh Zala
    Jan 17 '18 at 13:11











  • I have created form using ui-component

    – Jaisa
    Jan 17 '18 at 13:12













  • <uiComponent name="vendor_department_addform"/> wait am write full code in ans

    – Birjitsinh Zala
    Jan 17 '18 at 13:15














0












0








0








I need to add note to the form field using notice tag. for example



 <notice translate="true">Image size should be equal to some(here I
need to pass dynamic value)</notice>


form.xml



 <field name="image" sortOrder="60" formElement="fileUploader">
<settings>
<notice translate="true">Image size should be equal to some(here I need to pass dynamic value)</notice>
<label translate="true">Image</label>
<componentType>fileUploader</componentType>
<visible>true</visible>
</settings>
<formElements>
<fileUploader>
<settings>
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
<maxFileSize>102400</maxFileSize>
<uploaderConfig>
<param xsi:type="string" name="url">a/b/c</param>
</uploaderConfig>
<previewTmpl>x_y/image-preview</previewTmpl>
</settings>
</fileUploader>
</formElements>
</field>









share|improve this question
















I need to add note to the form field using notice tag. for example



 <notice translate="true">Image size should be equal to some(here I
need to pass dynamic value)</notice>


form.xml



 <field name="image" sortOrder="60" formElement="fileUploader">
<settings>
<notice translate="true">Image size should be equal to some(here I need to pass dynamic value)</notice>
<label translate="true">Image</label>
<componentType>fileUploader</componentType>
<visible>true</visible>
</settings>
<formElements>
<fileUploader>
<settings>
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
<maxFileSize>102400</maxFileSize>
<uploaderConfig>
<param xsi:type="string" name="url">a/b/c</param>
</uploaderConfig>
<previewTmpl>x_y/image-preview</previewTmpl>
</settings>
</fileUploader>
</formElements>
</field>






magento2.2 uicomponent adminform custom-field






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 17 '18 at 13:33







Jaisa

















asked Jan 17 '18 at 13:00









JaisaJaisa

9061940




9061940





bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • how to create form using ui-component? or simple

    – Birjitsinh Zala
    Jan 17 '18 at 13:11











  • I have created form using ui-component

    – Jaisa
    Jan 17 '18 at 13:12













  • <uiComponent name="vendor_department_addform"/> wait am write full code in ans

    – Birjitsinh Zala
    Jan 17 '18 at 13:15



















  • how to create form using ui-component? or simple

    – Birjitsinh Zala
    Jan 17 '18 at 13:11











  • I have created form using ui-component

    – Jaisa
    Jan 17 '18 at 13:12













  • <uiComponent name="vendor_department_addform"/> wait am write full code in ans

    – Birjitsinh Zala
    Jan 17 '18 at 13:15

















how to create form using ui-component? or simple

– Birjitsinh Zala
Jan 17 '18 at 13:11





how to create form using ui-component? or simple

– Birjitsinh Zala
Jan 17 '18 at 13:11













I have created form using ui-component

– Jaisa
Jan 17 '18 at 13:12







I have created form using ui-component

– Jaisa
Jan 17 '18 at 13:12















<uiComponent name="vendor_department_addform"/> wait am write full code in ans

– Birjitsinh Zala
Jan 17 '18 at 13:15





<uiComponent name="vendor_department_addform"/> wait am write full code in ans

– Birjitsinh Zala
Jan 17 '18 at 13:15










1 Answer
1






active

oldest

votes


















0














view/adminhtml/layout/form_index_index.xml



<body>
<referenceContainer name="content">
<uiComponent name="vendor_department_addform"/>
</referenceContainer>
</body>


view/adminhtml/ui_component/vendor_department_addform.xml



<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
<item name="deps" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Department Information</item>
<item name="layout" xsi:type="array">
<item name="type" xsi:type="string">tabs</item>
</item>
</argument>
<settings>
<buttons>
<button name="save" class="VendorModuleBlockAdminhtmlAddSaveButton"/>
<button name="reset" class="VendorModuleBlockAdminhtmlAddResetButton"/>
<button name="back" class="VendorModuleBlockAdminhtmlAddBackButton"/>
</buttons>
</settings>

<dataSource name="vendor_department_addform_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleModelDataProvider</argument>
<argument name="name" xsi:type="string">vendor_department_addform_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">department_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
<settings>
<submitUrl path="vendor/department/save"/>
</settings>
</dataSource>

<fieldset name="department_fieldset">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Add new department</item>
</item>
</argument>

<!-- This field represents form id and is hidden -->
<field name="department_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
</item>
</argument>
</field>
<!-- This field has data type 'text' and standard 'input' form element and looks like input -->
<field name="title">
<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">Title</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">title</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="identifier">
<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">Identifier</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">identifier</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="description">
<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">Description</item>
<item name="formElement" xsi:type="string">textarea</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">description</item>
</item>
</argument>
</field>
<field name="sort_order">
<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">Sort order</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">sort_order</item>
<item name="validation" xsi:type="array">
<item name="validate-number" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="status">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">VendorModuleModelDepartmentSourceSelectOption</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Status</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">status</item>
<!-- <item name="default" xsi:type="string">0</item> -->
</item>
</argument>
</field>
</fieldset>
</form>


VendorModuleModelDataProvider.php this is use for form data



namespace VendormoduleModel;

use VendormoduleModelResourceModelDepartmentCollectionFactory;

/**
* Class DataProvider
*/
class DataProvider extends MagentoUiDataProviderAbstractDataProvider
{
/**
* @var CustomModuleModelResourceModelMessagesCollection
*/
protected $collection;

/**
* @var array
*/
protected $loadedData;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $pageCollectionFactory
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $pageCollectionFactory,

array $meta = [],
array $data = []
) {
$this->collection = $pageCollectionFactory->create();
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->meta = $this->prepareMeta($this->meta);
}

/**
* Prepares Meta
*
* @param array $meta
* @return array
*/
public function prepareMeta(array $meta)
{
return $meta;
}

/**
* Get data
*
* @return array
*/
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
/** @var $page CustomModuleModelMessages */
foreach ($items as $page) {
$this->loadedData[$page->getId()] = $page->getData();
}
//echo "<pre>";print_r($this->loadedData);die;
return $this->loadedData;
}
}





share|improve this answer


























  • Thank you for your response, But my question is I need to add note to the form field. In that note message I need to pass dynamic values or data. For example <notice> Image size should be equal to some(here I need to pass dynamic value) size</notice>

    – Jaisa
    Jan 17 '18 at 13:24











  • dataprovider.php handle dynamic data

    – Birjitsinh Zala
    Jan 17 '18 at 13:27











  • Please see the updated post

    – Jaisa
    Jan 17 '18 at 13:30











  • <item name="component" xsi:type="string">Namespace_ModuleName/js/form/element/options</item> change using js

    – Birjitsinh Zala
    Jan 17 '18 at 13:48














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f209804%2fhow-do-we-can-give-dynamic-data-for-a-form-field-in-admin-formui-component-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














view/adminhtml/layout/form_index_index.xml



<body>
<referenceContainer name="content">
<uiComponent name="vendor_department_addform"/>
</referenceContainer>
</body>


view/adminhtml/ui_component/vendor_department_addform.xml



<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
<item name="deps" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Department Information</item>
<item name="layout" xsi:type="array">
<item name="type" xsi:type="string">tabs</item>
</item>
</argument>
<settings>
<buttons>
<button name="save" class="VendorModuleBlockAdminhtmlAddSaveButton"/>
<button name="reset" class="VendorModuleBlockAdminhtmlAddResetButton"/>
<button name="back" class="VendorModuleBlockAdminhtmlAddBackButton"/>
</buttons>
</settings>

<dataSource name="vendor_department_addform_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleModelDataProvider</argument>
<argument name="name" xsi:type="string">vendor_department_addform_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">department_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
<settings>
<submitUrl path="vendor/department/save"/>
</settings>
</dataSource>

<fieldset name="department_fieldset">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Add new department</item>
</item>
</argument>

<!-- This field represents form id and is hidden -->
<field name="department_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
</item>
</argument>
</field>
<!-- This field has data type 'text' and standard 'input' form element and looks like input -->
<field name="title">
<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">Title</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">title</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="identifier">
<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">Identifier</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">identifier</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="description">
<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">Description</item>
<item name="formElement" xsi:type="string">textarea</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">description</item>
</item>
</argument>
</field>
<field name="sort_order">
<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">Sort order</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">sort_order</item>
<item name="validation" xsi:type="array">
<item name="validate-number" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="status">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">VendorModuleModelDepartmentSourceSelectOption</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Status</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">status</item>
<!-- <item name="default" xsi:type="string">0</item> -->
</item>
</argument>
</field>
</fieldset>
</form>


VendorModuleModelDataProvider.php this is use for form data



namespace VendormoduleModel;

use VendormoduleModelResourceModelDepartmentCollectionFactory;

/**
* Class DataProvider
*/
class DataProvider extends MagentoUiDataProviderAbstractDataProvider
{
/**
* @var CustomModuleModelResourceModelMessagesCollection
*/
protected $collection;

/**
* @var array
*/
protected $loadedData;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $pageCollectionFactory
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $pageCollectionFactory,

array $meta = [],
array $data = []
) {
$this->collection = $pageCollectionFactory->create();
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->meta = $this->prepareMeta($this->meta);
}

/**
* Prepares Meta
*
* @param array $meta
* @return array
*/
public function prepareMeta(array $meta)
{
return $meta;
}

/**
* Get data
*
* @return array
*/
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
/** @var $page CustomModuleModelMessages */
foreach ($items as $page) {
$this->loadedData[$page->getId()] = $page->getData();
}
//echo "<pre>";print_r($this->loadedData);die;
return $this->loadedData;
}
}





share|improve this answer


























  • Thank you for your response, But my question is I need to add note to the form field. In that note message I need to pass dynamic values or data. For example <notice> Image size should be equal to some(here I need to pass dynamic value) size</notice>

    – Jaisa
    Jan 17 '18 at 13:24











  • dataprovider.php handle dynamic data

    – Birjitsinh Zala
    Jan 17 '18 at 13:27











  • Please see the updated post

    – Jaisa
    Jan 17 '18 at 13:30











  • <item name="component" xsi:type="string">Namespace_ModuleName/js/form/element/options</item> change using js

    – Birjitsinh Zala
    Jan 17 '18 at 13:48


















0














view/adminhtml/layout/form_index_index.xml



<body>
<referenceContainer name="content">
<uiComponent name="vendor_department_addform"/>
</referenceContainer>
</body>


view/adminhtml/ui_component/vendor_department_addform.xml



<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
<item name="deps" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Department Information</item>
<item name="layout" xsi:type="array">
<item name="type" xsi:type="string">tabs</item>
</item>
</argument>
<settings>
<buttons>
<button name="save" class="VendorModuleBlockAdminhtmlAddSaveButton"/>
<button name="reset" class="VendorModuleBlockAdminhtmlAddResetButton"/>
<button name="back" class="VendorModuleBlockAdminhtmlAddBackButton"/>
</buttons>
</settings>

<dataSource name="vendor_department_addform_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleModelDataProvider</argument>
<argument name="name" xsi:type="string">vendor_department_addform_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">department_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
<settings>
<submitUrl path="vendor/department/save"/>
</settings>
</dataSource>

<fieldset name="department_fieldset">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Add new department</item>
</item>
</argument>

<!-- This field represents form id and is hidden -->
<field name="department_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
</item>
</argument>
</field>
<!-- This field has data type 'text' and standard 'input' form element and looks like input -->
<field name="title">
<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">Title</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">title</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="identifier">
<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">Identifier</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">identifier</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="description">
<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">Description</item>
<item name="formElement" xsi:type="string">textarea</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">description</item>
</item>
</argument>
</field>
<field name="sort_order">
<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">Sort order</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">sort_order</item>
<item name="validation" xsi:type="array">
<item name="validate-number" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="status">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">VendorModuleModelDepartmentSourceSelectOption</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Status</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">status</item>
<!-- <item name="default" xsi:type="string">0</item> -->
</item>
</argument>
</field>
</fieldset>
</form>


VendorModuleModelDataProvider.php this is use for form data



namespace VendormoduleModel;

use VendormoduleModelResourceModelDepartmentCollectionFactory;

/**
* Class DataProvider
*/
class DataProvider extends MagentoUiDataProviderAbstractDataProvider
{
/**
* @var CustomModuleModelResourceModelMessagesCollection
*/
protected $collection;

/**
* @var array
*/
protected $loadedData;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $pageCollectionFactory
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $pageCollectionFactory,

array $meta = [],
array $data = []
) {
$this->collection = $pageCollectionFactory->create();
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->meta = $this->prepareMeta($this->meta);
}

/**
* Prepares Meta
*
* @param array $meta
* @return array
*/
public function prepareMeta(array $meta)
{
return $meta;
}

/**
* Get data
*
* @return array
*/
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
/** @var $page CustomModuleModelMessages */
foreach ($items as $page) {
$this->loadedData[$page->getId()] = $page->getData();
}
//echo "<pre>";print_r($this->loadedData);die;
return $this->loadedData;
}
}





share|improve this answer


























  • Thank you for your response, But my question is I need to add note to the form field. In that note message I need to pass dynamic values or data. For example <notice> Image size should be equal to some(here I need to pass dynamic value) size</notice>

    – Jaisa
    Jan 17 '18 at 13:24











  • dataprovider.php handle dynamic data

    – Birjitsinh Zala
    Jan 17 '18 at 13:27











  • Please see the updated post

    – Jaisa
    Jan 17 '18 at 13:30











  • <item name="component" xsi:type="string">Namespace_ModuleName/js/form/element/options</item> change using js

    – Birjitsinh Zala
    Jan 17 '18 at 13:48
















0












0








0







view/adminhtml/layout/form_index_index.xml



<body>
<referenceContainer name="content">
<uiComponent name="vendor_department_addform"/>
</referenceContainer>
</body>


view/adminhtml/ui_component/vendor_department_addform.xml



<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
<item name="deps" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Department Information</item>
<item name="layout" xsi:type="array">
<item name="type" xsi:type="string">tabs</item>
</item>
</argument>
<settings>
<buttons>
<button name="save" class="VendorModuleBlockAdminhtmlAddSaveButton"/>
<button name="reset" class="VendorModuleBlockAdminhtmlAddResetButton"/>
<button name="back" class="VendorModuleBlockAdminhtmlAddBackButton"/>
</buttons>
</settings>

<dataSource name="vendor_department_addform_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleModelDataProvider</argument>
<argument name="name" xsi:type="string">vendor_department_addform_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">department_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
<settings>
<submitUrl path="vendor/department/save"/>
</settings>
</dataSource>

<fieldset name="department_fieldset">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Add new department</item>
</item>
</argument>

<!-- This field represents form id and is hidden -->
<field name="department_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
</item>
</argument>
</field>
<!-- This field has data type 'text' and standard 'input' form element and looks like input -->
<field name="title">
<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">Title</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">title</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="identifier">
<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">Identifier</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">identifier</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="description">
<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">Description</item>
<item name="formElement" xsi:type="string">textarea</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">description</item>
</item>
</argument>
</field>
<field name="sort_order">
<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">Sort order</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">sort_order</item>
<item name="validation" xsi:type="array">
<item name="validate-number" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="status">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">VendorModuleModelDepartmentSourceSelectOption</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Status</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">status</item>
<!-- <item name="default" xsi:type="string">0</item> -->
</item>
</argument>
</field>
</fieldset>
</form>


VendorModuleModelDataProvider.php this is use for form data



namespace VendormoduleModel;

use VendormoduleModelResourceModelDepartmentCollectionFactory;

/**
* Class DataProvider
*/
class DataProvider extends MagentoUiDataProviderAbstractDataProvider
{
/**
* @var CustomModuleModelResourceModelMessagesCollection
*/
protected $collection;

/**
* @var array
*/
protected $loadedData;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $pageCollectionFactory
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $pageCollectionFactory,

array $meta = [],
array $data = []
) {
$this->collection = $pageCollectionFactory->create();
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->meta = $this->prepareMeta($this->meta);
}

/**
* Prepares Meta
*
* @param array $meta
* @return array
*/
public function prepareMeta(array $meta)
{
return $meta;
}

/**
* Get data
*
* @return array
*/
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
/** @var $page CustomModuleModelMessages */
foreach ($items as $page) {
$this->loadedData[$page->getId()] = $page->getData();
}
//echo "<pre>";print_r($this->loadedData);die;
return $this->loadedData;
}
}





share|improve this answer















view/adminhtml/layout/form_index_index.xml



<body>
<referenceContainer name="content">
<uiComponent name="vendor_department_addform"/>
</referenceContainer>
</body>


view/adminhtml/ui_component/vendor_department_addform.xml



<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
<item name="deps" xsi:type="string">vendor_department_addform.vendor_department_addform_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Department Information</item>
<item name="layout" xsi:type="array">
<item name="type" xsi:type="string">tabs</item>
</item>
</argument>
<settings>
<buttons>
<button name="save" class="VendorModuleBlockAdminhtmlAddSaveButton"/>
<button name="reset" class="VendorModuleBlockAdminhtmlAddResetButton"/>
<button name="back" class="VendorModuleBlockAdminhtmlAddBackButton"/>
</buttons>
</settings>

<dataSource name="vendor_department_addform_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">VendorModuleModelDataProvider</argument>
<argument name="name" xsi:type="string">vendor_department_addform_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">department_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
<settings>
<submitUrl path="vendor/department/save"/>
</settings>
</dataSource>

<fieldset name="department_fieldset">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Add new department</item>
</item>
</argument>

<!-- This field represents form id and is hidden -->
<field name="department_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
</item>
</argument>
</field>
<!-- This field has data type 'text' and standard 'input' form element and looks like input -->
<field name="title">
<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">Title</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">title</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="identifier">
<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">Identifier</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">identifier</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="description">
<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">Description</item>
<item name="formElement" xsi:type="string">textarea</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">description</item>
</item>
</argument>
</field>
<field name="sort_order">
<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">Sort order</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">sort_order</item>
<item name="validation" xsi:type="array">
<item name="validate-number" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
<field name="status">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">VendorModuleModelDepartmentSourceSelectOption</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Status</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">jobportal</item>
<item name="dataScope" xsi:type="string">status</item>
<!-- <item name="default" xsi:type="string">0</item> -->
</item>
</argument>
</field>
</fieldset>
</form>


VendorModuleModelDataProvider.php this is use for form data



namespace VendormoduleModel;

use VendormoduleModelResourceModelDepartmentCollectionFactory;

/**
* Class DataProvider
*/
class DataProvider extends MagentoUiDataProviderAbstractDataProvider
{
/**
* @var CustomModuleModelResourceModelMessagesCollection
*/
protected $collection;

/**
* @var array
*/
protected $loadedData;

/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $pageCollectionFactory
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $pageCollectionFactory,

array $meta = [],
array $data = []
) {
$this->collection = $pageCollectionFactory->create();
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->meta = $this->prepareMeta($this->meta);
}

/**
* Prepares Meta
*
* @param array $meta
* @return array
*/
public function prepareMeta(array $meta)
{
return $meta;
}

/**
* Get data
*
* @return array
*/
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
/** @var $page CustomModuleModelMessages */
foreach ($items as $page) {
$this->loadedData[$page->getId()] = $page->getData();
}
//echo "<pre>";print_r($this->loadedData);die;
return $this->loadedData;
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 17 '18 at 13:25

























answered Jan 17 '18 at 13:20









Birjitsinh ZalaBirjitsinh Zala

564115




564115













  • Thank you for your response, But my question is I need to add note to the form field. In that note message I need to pass dynamic values or data. For example <notice> Image size should be equal to some(here I need to pass dynamic value) size</notice>

    – Jaisa
    Jan 17 '18 at 13:24











  • dataprovider.php handle dynamic data

    – Birjitsinh Zala
    Jan 17 '18 at 13:27











  • Please see the updated post

    – Jaisa
    Jan 17 '18 at 13:30











  • <item name="component" xsi:type="string">Namespace_ModuleName/js/form/element/options</item> change using js

    – Birjitsinh Zala
    Jan 17 '18 at 13:48





















  • Thank you for your response, But my question is I need to add note to the form field. In that note message I need to pass dynamic values or data. For example <notice> Image size should be equal to some(here I need to pass dynamic value) size</notice>

    – Jaisa
    Jan 17 '18 at 13:24











  • dataprovider.php handle dynamic data

    – Birjitsinh Zala
    Jan 17 '18 at 13:27











  • Please see the updated post

    – Jaisa
    Jan 17 '18 at 13:30











  • <item name="component" xsi:type="string">Namespace_ModuleName/js/form/element/options</item> change using js

    – Birjitsinh Zala
    Jan 17 '18 at 13:48



















Thank you for your response, But my question is I need to add note to the form field. In that note message I need to pass dynamic values or data. For example <notice> Image size should be equal to some(here I need to pass dynamic value) size</notice>

– Jaisa
Jan 17 '18 at 13:24





Thank you for your response, But my question is I need to add note to the form field. In that note message I need to pass dynamic values or data. For example <notice> Image size should be equal to some(here I need to pass dynamic value) size</notice>

– Jaisa
Jan 17 '18 at 13:24













dataprovider.php handle dynamic data

– Birjitsinh Zala
Jan 17 '18 at 13:27





dataprovider.php handle dynamic data

– Birjitsinh Zala
Jan 17 '18 at 13:27













Please see the updated post

– Jaisa
Jan 17 '18 at 13:30





Please see the updated post

– Jaisa
Jan 17 '18 at 13:30













<item name="component" xsi:type="string">Namespace_ModuleName/js/form/element/options</item> change using js

– Birjitsinh Zala
Jan 17 '18 at 13:48







<item name="component" xsi:type="string">Namespace_ModuleName/js/form/element/options</item> change using js

– Birjitsinh Zala
Jan 17 '18 at 13:48




















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f209804%2fhow-do-we-can-give-dynamic-data-for-a-form-field-in-admin-formui-component-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

“%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...