Add a note under a form field using ui components Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar ManaraField comments in ui_component formData population in UI formHow to make a form field readonly using ui-components?Magento2: Unable to post 2D Array from REST ApiHow to add an image uploader (to record an image and its path in the Magento store config) to the admin form, using .xml files?How to add a link in ui form component note?Magento 2 : How can I upload files of dynamically added file input fields in the adminMagento2: Adding custom fields on checkout are not associated with the formHow to add field to this formSet default values for a multiselect ui-componentMagento2: how to add/remove a form field using javascript
Can I criticise the more senior developers around me for not writing clean code?
Did the Roman Empire have penal colonies?
Check if a string is entirely made of the same substring
How to keep bees out of canned beverages?
Suing a Police Officer Instead of the Police Department
With indentation set to `0em`, when using a line break, there is still an indentation of a size of a space
Is a 5 watt UHF/VHF handheld considered QRP?
What is the term for a person whose job is to place products on shelves in stores?
Passing args from the bash script to the function in the script
Retract an already submitted recommendation letter (written for an undergrad student)
Does Feeblemind produce an ongoing magical effect that can be dispelled?
As an international instructor, should I openly talk about my accent?
What's parked in Mil Moscow helicopter plant?
Split coins into combinations of different denominations
Mistake in years of experience in resume?
How to open locks without disable device?
Book with legacy programming code on a space ship that the main character hacks to escape
How to use @AuraEnabled base class method in Lightning Component?
Is accepting an invalid credit card number a security issue?
Why isn't everyone flabbergasted about Bran's "gift"?
How to avoid introduction cliches
Will I lose my paid in full property
I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
Add a note under a form field using ui components
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraField comments in ui_component formData population in UI formHow to make a form field readonly using ui-components?Magento2: Unable to post 2D Array from REST ApiHow to add an image uploader (to record an image and its path in the Magento store config) to the admin form, using .xml files?How to add a link in ui form component note?Magento 2 : How can I upload files of dynamically added file input fields in the adminMagento2: Adding custom fields on checkout are not associated with the formHow to add field to this formSet default values for a multiselect ui-componentMagento2: how to add/remove a form field using javascript
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How can I add a small text under a field in Magento 2 using ui components.
Using MagentoFrameworkDataForm
I could do this:
/** @var MagentoFrameworkDataForm $form */
$form = $this->formFactory->create();
$fieldset = $form->addFieldset(
'base_fieldset',
[
'legend' => __('Some legend here'),
'class' => 'fieldset-wide'
]
);
$fieldset->addField(
'name',
'text',
[
'name' => 'name',
'label' => __('Name'),
'title' => __('Name'),
'note' => __('Some note here')
]
);
The code above would produce this (notice the text under the field).
How can I achieve the same thing using form ui-components?
I have the form defined like this:
<field name="name">
<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">Name</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">[entity]</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="dataScope" xsi:type="string">name</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
I tried adding <item name="note" xsi:type="string" translate="true">Some note here</item>
but, guess what?
magento-2.0 forms uicomponent
add a comment |
How can I add a small text under a field in Magento 2 using ui components.
Using MagentoFrameworkDataForm
I could do this:
/** @var MagentoFrameworkDataForm $form */
$form = $this->formFactory->create();
$fieldset = $form->addFieldset(
'base_fieldset',
[
'legend' => __('Some legend here'),
'class' => 'fieldset-wide'
]
);
$fieldset->addField(
'name',
'text',
[
'name' => 'name',
'label' => __('Name'),
'title' => __('Name'),
'note' => __('Some note here')
]
);
The code above would produce this (notice the text under the field).
How can I achieve the same thing using form ui-components?
I have the form defined like this:
<field name="name">
<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">Name</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">[entity]</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="dataScope" xsi:type="string">name</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
I tried adding <item name="note" xsi:type="string" translate="true">Some note here</item>
but, guess what?
magento-2.0 forms uicomponent
add a comment |
How can I add a small text under a field in Magento 2 using ui components.
Using MagentoFrameworkDataForm
I could do this:
/** @var MagentoFrameworkDataForm $form */
$form = $this->formFactory->create();
$fieldset = $form->addFieldset(
'base_fieldset',
[
'legend' => __('Some legend here'),
'class' => 'fieldset-wide'
]
);
$fieldset->addField(
'name',
'text',
[
'name' => 'name',
'label' => __('Name'),
'title' => __('Name'),
'note' => __('Some note here')
]
);
The code above would produce this (notice the text under the field).
How can I achieve the same thing using form ui-components?
I have the form defined like this:
<field name="name">
<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">Name</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">[entity]</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="dataScope" xsi:type="string">name</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
I tried adding <item name="note" xsi:type="string" translate="true">Some note here</item>
but, guess what?
magento-2.0 forms uicomponent
How can I add a small text under a field in Magento 2 using ui components.
Using MagentoFrameworkDataForm
I could do this:
/** @var MagentoFrameworkDataForm $form */
$form = $this->formFactory->create();
$fieldset = $form->addFieldset(
'base_fieldset',
[
'legend' => __('Some legend here'),
'class' => 'fieldset-wide'
]
);
$fieldset->addField(
'name',
'text',
[
'name' => 'name',
'label' => __('Name'),
'title' => __('Name'),
'note' => __('Some note here')
]
);
The code above would produce this (notice the text under the field).
How can I achieve the same thing using form ui-components?
I have the form defined like this:
<field name="name">
<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">Name</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">[entity]</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="dataScope" xsi:type="string">name</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
I tried adding <item name="note" xsi:type="string" translate="true">Some note here</item>
but, guess what?
magento-2.0 forms uicomponent
magento-2.0 forms uicomponent
edited Jun 20 '17 at 8:22
Marius
asked May 26 '16 at 6:33
Marius♦Marius
168k28324694
168k28324694
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can achieve this using following tag.
<item name="notice" xsi:type="string" translate="true">Some note here</item>
Thanks. It works. I addedtranslate="true"
just to make the translatable phrase collector script pick this up also.
– Marius♦
May 26 '16 at 7:22
@Marius do you know how to use html code in notice?
– Sergey Korzhov
Jun 20 '17 at 8:08
@SergeyKorzhov try<item name="notice" xsi:type="string" translate="true"><![CDATA[Some note <a href="https://google.com">here</a>]]></item>
– Marius♦
Jun 20 '17 at 8:14
@Marius i did before asking. does not work. the funny thing is that html works just fine in system.xml even without CDATA.
– Sergey Korzhov
Jun 20 '17 at 8:21
In this notice , shall I give dynamic data inbetween messages ?? Is this possible @Marius
– Jaisa
Jan 17 '18 at 13:20
|
show 1 more comment
I had a really annoying time figuring out how to get html to render in a notice object. There have been two solutions I have figured out. I know this could possibly be a comment, but I figured other people would be interested in this functionality as well.
- Create a new html element that renders the notice as HTML instead of text
the original element can be found at /vendor/magento/module-ui/view/base/web/templates/form/field.html
Copy that into your module with a path of view/base/web/template/form/field-html-notice.html
or something similar (please note the templates
directory being changed to template
that is intentional and required for custom template files)
Now in your new field-html-notice.html file, you can modify the html file to load the $data.notice
using html and skip the span altogether. (of course if you're looking to translate your html, you'll need to customise this solution to have some workaround)
The solution would be to take this template and modify
<!-- /vendor/magento/module-ui/view/base/web/templates/form/field.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId">
<span translate="notice"/>
</div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
to look something more like this:
<!-- view/base/web/template/form/field-html-notice.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId" html="$data.notice"></div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
Once I had taken the time to do that, I realised the Magento team has conveniently given us the ability to add additionalInfo
that is rendered as html.
- Add a div with the notice class as additional info for a component
The much tackier option would be to have the notice div render in the additionalInfo
section.
Something along the lines of
<!-- my_cool_component.xml -->
<field name="field_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!-- other field config -->
<item name="additionalInfo" xsi:type="string" translate="true">
<div class="admin__field-note">
This looks like a notice<br/>
it is super <span style="font-weight=bold">TACKY</span><br/>
but it will work <a href="http://google.com">I promise</a>
</div>
</item>
</item>
</argument>
</field>
So yeah, simple right? Well. I'm going to go sleep now.
(please note that the xml validator will break if you use the actual <
or >
characters in your additional info, hence the <
and >
Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
Thanks @Marius
1
<item name="additionalInfo" xsi:type="string" translate="true"> works a lot better then notice
– CompactCode
Jun 7 '18 at 16:57
<![CDATA[<p>cool paragraph man</p>]]
Does not work undermessage
but it works withadditionalInfo
mag.2.2.2
– Juliano Vargas
Feb 11 at 12:31
add a comment |
The current Magento 2 versions 2.2.8 and 2.3.1 both supports the html additionalInfo by default in UI Form field.
<item name="additionalInfo" xsi:type="string"><![CDATA[<b>My Html Information</b>]]>
</item>
No need to modify the field.html template.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f117039%2fadd-a-note-under-a-form-field-using-ui-components%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can achieve this using following tag.
<item name="notice" xsi:type="string" translate="true">Some note here</item>
Thanks. It works. I addedtranslate="true"
just to make the translatable phrase collector script pick this up also.
– Marius♦
May 26 '16 at 7:22
@Marius do you know how to use html code in notice?
– Sergey Korzhov
Jun 20 '17 at 8:08
@SergeyKorzhov try<item name="notice" xsi:type="string" translate="true"><![CDATA[Some note <a href="https://google.com">here</a>]]></item>
– Marius♦
Jun 20 '17 at 8:14
@Marius i did before asking. does not work. the funny thing is that html works just fine in system.xml even without CDATA.
– Sergey Korzhov
Jun 20 '17 at 8:21
In this notice , shall I give dynamic data inbetween messages ?? Is this possible @Marius
– Jaisa
Jan 17 '18 at 13:20
|
show 1 more comment
You can achieve this using following tag.
<item name="notice" xsi:type="string" translate="true">Some note here</item>
Thanks. It works. I addedtranslate="true"
just to make the translatable phrase collector script pick this up also.
– Marius♦
May 26 '16 at 7:22
@Marius do you know how to use html code in notice?
– Sergey Korzhov
Jun 20 '17 at 8:08
@SergeyKorzhov try<item name="notice" xsi:type="string" translate="true"><![CDATA[Some note <a href="https://google.com">here</a>]]></item>
– Marius♦
Jun 20 '17 at 8:14
@Marius i did before asking. does not work. the funny thing is that html works just fine in system.xml even without CDATA.
– Sergey Korzhov
Jun 20 '17 at 8:21
In this notice , shall I give dynamic data inbetween messages ?? Is this possible @Marius
– Jaisa
Jan 17 '18 at 13:20
|
show 1 more comment
You can achieve this using following tag.
<item name="notice" xsi:type="string" translate="true">Some note here</item>
You can achieve this using following tag.
<item name="notice" xsi:type="string" translate="true">Some note here</item>
edited May 26 '16 at 7:22
Marius♦
168k28324694
168k28324694
answered May 26 '16 at 7:13
Sohel RanaSohel Rana
23.5k34461
23.5k34461
Thanks. It works. I addedtranslate="true"
just to make the translatable phrase collector script pick this up also.
– Marius♦
May 26 '16 at 7:22
@Marius do you know how to use html code in notice?
– Sergey Korzhov
Jun 20 '17 at 8:08
@SergeyKorzhov try<item name="notice" xsi:type="string" translate="true"><![CDATA[Some note <a href="https://google.com">here</a>]]></item>
– Marius♦
Jun 20 '17 at 8:14
@Marius i did before asking. does not work. the funny thing is that html works just fine in system.xml even without CDATA.
– Sergey Korzhov
Jun 20 '17 at 8:21
In this notice , shall I give dynamic data inbetween messages ?? Is this possible @Marius
– Jaisa
Jan 17 '18 at 13:20
|
show 1 more comment
Thanks. It works. I addedtranslate="true"
just to make the translatable phrase collector script pick this up also.
– Marius♦
May 26 '16 at 7:22
@Marius do you know how to use html code in notice?
– Sergey Korzhov
Jun 20 '17 at 8:08
@SergeyKorzhov try<item name="notice" xsi:type="string" translate="true"><![CDATA[Some note <a href="https://google.com">here</a>]]></item>
– Marius♦
Jun 20 '17 at 8:14
@Marius i did before asking. does not work. the funny thing is that html works just fine in system.xml even without CDATA.
– Sergey Korzhov
Jun 20 '17 at 8:21
In this notice , shall I give dynamic data inbetween messages ?? Is this possible @Marius
– Jaisa
Jan 17 '18 at 13:20
Thanks. It works. I added
translate="true"
just to make the translatable phrase collector script pick this up also.– Marius♦
May 26 '16 at 7:22
Thanks. It works. I added
translate="true"
just to make the translatable phrase collector script pick this up also.– Marius♦
May 26 '16 at 7:22
@Marius do you know how to use html code in notice?
– Sergey Korzhov
Jun 20 '17 at 8:08
@Marius do you know how to use html code in notice?
– Sergey Korzhov
Jun 20 '17 at 8:08
@SergeyKorzhov try
<item name="notice" xsi:type="string" translate="true"><![CDATA[Some note <a href="https://google.com">here</a>]]></item>
– Marius♦
Jun 20 '17 at 8:14
@SergeyKorzhov try
<item name="notice" xsi:type="string" translate="true"><![CDATA[Some note <a href="https://google.com">here</a>]]></item>
– Marius♦
Jun 20 '17 at 8:14
@Marius i did before asking. does not work. the funny thing is that html works just fine in system.xml even without CDATA.
– Sergey Korzhov
Jun 20 '17 at 8:21
@Marius i did before asking. does not work. the funny thing is that html works just fine in system.xml even without CDATA.
– Sergey Korzhov
Jun 20 '17 at 8:21
In this notice , shall I give dynamic data inbetween messages ?? Is this possible @Marius
– Jaisa
Jan 17 '18 at 13:20
In this notice , shall I give dynamic data inbetween messages ?? Is this possible @Marius
– Jaisa
Jan 17 '18 at 13:20
|
show 1 more comment
I had a really annoying time figuring out how to get html to render in a notice object. There have been two solutions I have figured out. I know this could possibly be a comment, but I figured other people would be interested in this functionality as well.
- Create a new html element that renders the notice as HTML instead of text
the original element can be found at /vendor/magento/module-ui/view/base/web/templates/form/field.html
Copy that into your module with a path of view/base/web/template/form/field-html-notice.html
or something similar (please note the templates
directory being changed to template
that is intentional and required for custom template files)
Now in your new field-html-notice.html file, you can modify the html file to load the $data.notice
using html and skip the span altogether. (of course if you're looking to translate your html, you'll need to customise this solution to have some workaround)
The solution would be to take this template and modify
<!-- /vendor/magento/module-ui/view/base/web/templates/form/field.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId">
<span translate="notice"/>
</div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
to look something more like this:
<!-- view/base/web/template/form/field-html-notice.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId" html="$data.notice"></div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
Once I had taken the time to do that, I realised the Magento team has conveniently given us the ability to add additionalInfo
that is rendered as html.
- Add a div with the notice class as additional info for a component
The much tackier option would be to have the notice div render in the additionalInfo
section.
Something along the lines of
<!-- my_cool_component.xml -->
<field name="field_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!-- other field config -->
<item name="additionalInfo" xsi:type="string" translate="true">
<div class="admin__field-note">
This looks like a notice<br/>
it is super <span style="font-weight=bold">TACKY</span><br/>
but it will work <a href="http://google.com">I promise</a>
</div>
</item>
</item>
</argument>
</field>
So yeah, simple right? Well. I'm going to go sleep now.
(please note that the xml validator will break if you use the actual <
or >
characters in your additional info, hence the <
and >
Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
Thanks @Marius
1
<item name="additionalInfo" xsi:type="string" translate="true"> works a lot better then notice
– CompactCode
Jun 7 '18 at 16:57
<![CDATA[<p>cool paragraph man</p>]]
Does not work undermessage
but it works withadditionalInfo
mag.2.2.2
– Juliano Vargas
Feb 11 at 12:31
add a comment |
I had a really annoying time figuring out how to get html to render in a notice object. There have been two solutions I have figured out. I know this could possibly be a comment, but I figured other people would be interested in this functionality as well.
- Create a new html element that renders the notice as HTML instead of text
the original element can be found at /vendor/magento/module-ui/view/base/web/templates/form/field.html
Copy that into your module with a path of view/base/web/template/form/field-html-notice.html
or something similar (please note the templates
directory being changed to template
that is intentional and required for custom template files)
Now in your new field-html-notice.html file, you can modify the html file to load the $data.notice
using html and skip the span altogether. (of course if you're looking to translate your html, you'll need to customise this solution to have some workaround)
The solution would be to take this template and modify
<!-- /vendor/magento/module-ui/view/base/web/templates/form/field.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId">
<span translate="notice"/>
</div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
to look something more like this:
<!-- view/base/web/template/form/field-html-notice.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId" html="$data.notice"></div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
Once I had taken the time to do that, I realised the Magento team has conveniently given us the ability to add additionalInfo
that is rendered as html.
- Add a div with the notice class as additional info for a component
The much tackier option would be to have the notice div render in the additionalInfo
section.
Something along the lines of
<!-- my_cool_component.xml -->
<field name="field_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!-- other field config -->
<item name="additionalInfo" xsi:type="string" translate="true">
<div class="admin__field-note">
This looks like a notice<br/>
it is super <span style="font-weight=bold">TACKY</span><br/>
but it will work <a href="http://google.com">I promise</a>
</div>
</item>
</item>
</argument>
</field>
So yeah, simple right? Well. I'm going to go sleep now.
(please note that the xml validator will break if you use the actual <
or >
characters in your additional info, hence the <
and >
Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
Thanks @Marius
1
<item name="additionalInfo" xsi:type="string" translate="true"> works a lot better then notice
– CompactCode
Jun 7 '18 at 16:57
<![CDATA[<p>cool paragraph man</p>]]
Does not work undermessage
but it works withadditionalInfo
mag.2.2.2
– Juliano Vargas
Feb 11 at 12:31
add a comment |
I had a really annoying time figuring out how to get html to render in a notice object. There have been two solutions I have figured out. I know this could possibly be a comment, but I figured other people would be interested in this functionality as well.
- Create a new html element that renders the notice as HTML instead of text
the original element can be found at /vendor/magento/module-ui/view/base/web/templates/form/field.html
Copy that into your module with a path of view/base/web/template/form/field-html-notice.html
or something similar (please note the templates
directory being changed to template
that is intentional and required for custom template files)
Now in your new field-html-notice.html file, you can modify the html file to load the $data.notice
using html and skip the span altogether. (of course if you're looking to translate your html, you'll need to customise this solution to have some workaround)
The solution would be to take this template and modify
<!-- /vendor/magento/module-ui/view/base/web/templates/form/field.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId">
<span translate="notice"/>
</div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
to look something more like this:
<!-- view/base/web/template/form/field-html-notice.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId" html="$data.notice"></div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
Once I had taken the time to do that, I realised the Magento team has conveniently given us the ability to add additionalInfo
that is rendered as html.
- Add a div with the notice class as additional info for a component
The much tackier option would be to have the notice div render in the additionalInfo
section.
Something along the lines of
<!-- my_cool_component.xml -->
<field name="field_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!-- other field config -->
<item name="additionalInfo" xsi:type="string" translate="true">
<div class="admin__field-note">
This looks like a notice<br/>
it is super <span style="font-weight=bold">TACKY</span><br/>
but it will work <a href="http://google.com">I promise</a>
</div>
</item>
</item>
</argument>
</field>
So yeah, simple right? Well. I'm going to go sleep now.
(please note that the xml validator will break if you use the actual <
or >
characters in your additional info, hence the <
and >
Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
Thanks @Marius
I had a really annoying time figuring out how to get html to render in a notice object. There have been two solutions I have figured out. I know this could possibly be a comment, but I figured other people would be interested in this functionality as well.
- Create a new html element that renders the notice as HTML instead of text
the original element can be found at /vendor/magento/module-ui/view/base/web/templates/form/field.html
Copy that into your module with a path of view/base/web/template/form/field-html-notice.html
or something similar (please note the templates
directory being changed to template
that is intentional and required for custom template files)
Now in your new field-html-notice.html file, you can modify the html file to load the $data.notice
using html and skip the span altogether. (of course if you're looking to translate your html, you'll need to customise this solution to have some workaround)
The solution would be to take this template and modify
<!-- /vendor/magento/module-ui/view/base/web/templates/form/field.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId">
<span translate="notice"/>
</div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
to look something more like this:
<!-- view/base/web/template/form/field-html-notice.html:35 -->
<div class="admin__field-note" if="$data.notice" attr="id: noticeId" html="$data.notice"></div>
<div class="admin__additional-info" if="$data.additionalInfo" html="$data.additionalInfo"></div>
Once I had taken the time to do that, I realised the Magento team has conveniently given us the ability to add additionalInfo
that is rendered as html.
- Add a div with the notice class as additional info for a component
The much tackier option would be to have the notice div render in the additionalInfo
section.
Something along the lines of
<!-- my_cool_component.xml -->
<field name="field_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!-- other field config -->
<item name="additionalInfo" xsi:type="string" translate="true">
<div class="admin__field-note">
This looks like a notice<br/>
it is super <span style="font-weight=bold">TACKY</span><br/>
but it will work <a href="http://google.com">I promise</a>
</div>
</item>
</item>
</argument>
</field>
So yeah, simple right? Well. I'm going to go sleep now.
(please note that the xml validator will break if you use the actual <
or >
characters in your additional info, hence the <
and >
Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
Thanks @Marius
answered Feb 13 '18 at 2:43
Nathaniel RogersNathaniel Rogers
9316
9316
1
<item name="additionalInfo" xsi:type="string" translate="true"> works a lot better then notice
– CompactCode
Jun 7 '18 at 16:57
<![CDATA[<p>cool paragraph man</p>]]
Does not work undermessage
but it works withadditionalInfo
mag.2.2.2
– Juliano Vargas
Feb 11 at 12:31
add a comment |
1
<item name="additionalInfo" xsi:type="string" translate="true"> works a lot better then notice
– CompactCode
Jun 7 '18 at 16:57
<![CDATA[<p>cool paragraph man</p>]]
Does not work undermessage
but it works withadditionalInfo
mag.2.2.2
– Juliano Vargas
Feb 11 at 12:31
1
1
<item name="additionalInfo" xsi:type="string" translate="true"> works a lot better then notice
– CompactCode
Jun 7 '18 at 16:57
<item name="additionalInfo" xsi:type="string" translate="true"> works a lot better then notice
– CompactCode
Jun 7 '18 at 16:57
<![CDATA[<p>cool paragraph man</p>]]
Does not work under message
but it works with additionalInfo
mag.2.2.2– Juliano Vargas
Feb 11 at 12:31
<![CDATA[<p>cool paragraph man</p>]]
Does not work under message
but it works with additionalInfo
mag.2.2.2– Juliano Vargas
Feb 11 at 12:31
add a comment |
The current Magento 2 versions 2.2.8 and 2.3.1 both supports the html additionalInfo by default in UI Form field.
<item name="additionalInfo" xsi:type="string"><![CDATA[<b>My Html Information</b>]]>
</item>
No need to modify the field.html template.
add a comment |
The current Magento 2 versions 2.2.8 and 2.3.1 both supports the html additionalInfo by default in UI Form field.
<item name="additionalInfo" xsi:type="string"><![CDATA[<b>My Html Information</b>]]>
</item>
No need to modify the field.html template.
add a comment |
The current Magento 2 versions 2.2.8 and 2.3.1 both supports the html additionalInfo by default in UI Form field.
<item name="additionalInfo" xsi:type="string"><![CDATA[<b>My Html Information</b>]]>
</item>
No need to modify the field.html template.
The current Magento 2 versions 2.2.8 and 2.3.1 both supports the html additionalInfo by default in UI Form field.
<item name="additionalInfo" xsi:type="string"><![CDATA[<b>My Html Information</b>]]>
</item>
No need to modify the field.html template.
answered 2 days ago
Milind SinghMilind Singh
688215
688215
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f117039%2fadd-a-note-under-a-form-field-using-ui-components%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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