2

I want to add a field like Street address in my custom module. same as customer Address Add from back-end form. it will look like below image. enter image description here

How can I add this kind of field using the UI component?


UPDATE:

I have used the below code to display a multiline component. But it is not displaying a filed label.

<field name="address">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="component" xsi:type="string" translate="true">Magento_Ui/js/form/components/group</item>
 <item name="dataType" xsi:type="string">text</item>
 <item name="size" xsi:type="number">2</item>
 <item name="formElement" xsi:type="string">multiline</item>
 <item name="visible" xsi:type="boolean">true</item>
 <item name="source" xsi:type="string">store</item>
 <item name="validation" xsi:type="array">
 <item name="required-entry" xsi:type="boolean">true</item>
 </item>
 </item>
 <item name="label" xsi:type="string" translate="true">Street</item>
 </argument>
 </field>

And also I would like to create a field using a new UI-component form method, the above code is an older method.

Any help would be appreciated!

Rohan Hapani
17.6k9 gold badges57 silver badges99 bronze badges
asked Aug 23, 2019 at 12:40
11
  • Fields & label both are not displaying or just label not displaying? Commented Aug 26, 2019 at 7:04
  • Field display but, only label not displaying. Commented Aug 26, 2019 at 7:07
  • I found that it is default magento bug github.com/magento/magento2/issues/7428 Commented Aug 26, 2019 at 7:20
  • Now need to know how to implement a patch of this issue. Commented Aug 26, 2019 at 7:21
  • 1
    I will try and let you know. Thanks. +1 for the help :) Commented Aug 26, 2019 at 10:53

1 Answer 1

2

About multiline fields data, it's render from vendor/magento/module-ui/Component/Form/Element/Multiline.php file.

It seems like there are no label fields added before prepare data. So, you need to override the file or use plugin for that.

For testing, you can write code in core file and add this below code :

vendor/magento/module-ui/Component/Form/Element/Multiline.php

public function prepare() {
 $size = abs((int) $this->getData('config/size'));
 $validation = [$this->getData('config/validation')];
 while ($size--) {
 $identifier = $this->getName() . '_' . $size;
 $arguments = [
 'data' => [
 'name' => $identifier,
 'config' => [
 'dataScope' => $size,
 'dataType' => static::DATA_TYPE,
 'formElement' => static::FORM_ELEMENT,
 'sortOrder' => $size,
 ],
 ],
 ];
 if (!empty($validation[$size])) {
 $arguments['data']['config']['validation'] = $validation[$size];
 }
 // For display label
 if($this->getData('config/formElement') == 'multiline' && $this->getData('config/label') != ''){
 $arguments['data']['config']['label'] = $this->getData('config/label');
 }
 $component = $this->uiComponentFactory->create($identifier, Field::NAME, $arguments);
 $component->prepare();
 $this->components[$identifier] = $component;
 }
 parent::prepare();
}

Note : I do not recommended to change in core files. Create plugins for that.

answered Aug 26, 2019 at 10:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.