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;








16















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?










share|improve this question






























    16















    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?










    share|improve this question


























      16












      16








      16


      6






      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 20 '17 at 8:22







      Marius

















      asked May 26 '16 at 6:33









      MariusMarius

      168k28324694




      168k28324694




















          3 Answers
          3






          active

          oldest

          votes


















          28














          You can achieve this using following tag.



          <item name="notice" xsi:type="string" translate="true">Some note here</item>





          share|improve this answer

























          • 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











          • @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


















          3














          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.



          1. 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.



          1. 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">
          &lt;div class="admin__field-note"&gt;
          This looks like a notice&lt;br/&gt;
          it is super &ltspan style="font-weight=bold"&gt;TACKY&lt/span&gt;&lt;br/&gt;
          but it will work &lta href="http://google.com"&gt;I promise&lt/a&gt;
          &lt;/div&gt;
          </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 &lt; and &gt;



          Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
          Thanks @Marius






          share|improve this answer


















          • 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 under message but it works with additionalInfo mag.2.2.2

            – Juliano Vargas
            Feb 11 at 12:31


















          1














          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.






          share|improve this answer























            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%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









            28














            You can achieve this using following tag.



            <item name="notice" xsi:type="string" translate="true">Some note here</item>





            share|improve this answer

























            • 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











            • @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















            28














            You can achieve this using following tag.



            <item name="notice" xsi:type="string" translate="true">Some note here</item>





            share|improve this answer

























            • 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











            • @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













            28












            28








            28







            You can achieve this using following tag.



            <item name="notice" xsi:type="string" translate="true">Some note here</item>





            share|improve this answer















            You can achieve this using following tag.



            <item name="notice" xsi:type="string" translate="true">Some note here</item>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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 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











            • @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











            • @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













            3














            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.



            1. 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.



            1. 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">
            &lt;div class="admin__field-note"&gt;
            This looks like a notice&lt;br/&gt;
            it is super &ltspan style="font-weight=bold"&gt;TACKY&lt/span&gt;&lt;br/&gt;
            but it will work &lta href="http://google.com"&gt;I promise&lt/a&gt;
            &lt;/div&gt;
            </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 &lt; and &gt;



            Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
            Thanks @Marius






            share|improve this answer


















            • 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 under message but it works with additionalInfo mag.2.2.2

              – Juliano Vargas
              Feb 11 at 12:31















            3














            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.



            1. 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.



            1. 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">
            &lt;div class="admin__field-note"&gt;
            This looks like a notice&lt;br/&gt;
            it is super &ltspan style="font-weight=bold"&gt;TACKY&lt/span&gt;&lt;br/&gt;
            but it will work &lta href="http://google.com"&gt;I promise&lt/a&gt;
            &lt;/div&gt;
            </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 &lt; and &gt;



            Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
            Thanks @Marius






            share|improve this answer


















            • 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 under message but it works with additionalInfo mag.2.2.2

              – Juliano Vargas
              Feb 11 at 12:31













            3












            3








            3







            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.



            1. 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.



            1. 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">
            &lt;div class="admin__field-note"&gt;
            This looks like a notice&lt;br/&gt;
            it is super &ltspan style="font-weight=bold"&gt;TACKY&lt/span&gt;&lt;br/&gt;
            but it will work &lta href="http://google.com"&gt;I promise&lt/a&gt;
            &lt;/div&gt;
            </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 &lt; and &gt;



            Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
            Thanks @Marius






            share|improve this answer













            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.



            1. 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.



            1. 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">
            &lt;div class="admin__field-note"&gt;
            This looks like a notice&lt;br/&gt;
            it is super &ltspan style="font-weight=bold"&gt;TACKY&lt/span&gt;&lt;br/&gt;
            but it will work &lta href="http://google.com"&gt;I promise&lt/a&gt;
            &lt;/div&gt;
            </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 &lt; and &gt;



            Note: turns out you can just wrap your html in <![CDATA[<p>cool paragraph man</p>]]
            Thanks @Marius







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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 under message but it works with additionalInfo mag.2.2.2

              – Juliano Vargas
              Feb 11 at 12:31












            • 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 under message but it works with additionalInfo 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











            1














            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.






            share|improve this answer



























              1














              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.






              share|improve this answer

























                1












                1








                1







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                Milind SinghMilind Singh

                688215




                688215



























                    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%2f117039%2fadd-a-note-under-a-form-field-using-ui-components%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

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?