6

I've faced with a problem. I have to render price input type in the customer edit form on the backend. I have found that the price component has been declared in the definition.xml like this:

<price class="Magento\Ui\Component\Form\Element\DataType\Price"/>

So, I have created own definition.xml file in the view/base/ui_component/etc/definition.xml:

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_definition.xsd">
    <!-- Price elements -->
    <price class="Magento\Ui\Component\Form\Element\DataType\Price">
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/element/abstract</item>
                <item name="config" xsi:type="array">
                    <item name="template" xsi:type="string">ui/form/field</item>
                    <item name="elementTmpl" xsi:type="string">ui/form/element/price</item>
                </item>
            </item>
        </argument>
    </price>
</components>

Unfortunately, XSD validation avoid this change from appling and I have got the following issue:

Element 'components': Missing child element(s). Expected is one of ( tab, dataSource, paging, massaction, listing, form, fieldset, field, filters, columns ). Line: 2

I have read the magento 2 developer guid ( http://devdocs.magento.com/guides/v2.0/ui-components/ui-component.html ) :

Any module can introduce its own set of custom components or modify initial configuration for existing components in a common to Magento way

Well, I have used "the common way", haven't I?

I would glad to read your ideas about this issue and ways in which we can reconfigurate the ui component via xml declaration.

3

Not sure if this will help so many months later, but definition.xml is where a UI Component's default configuration gets created. When Magento uses a particular node in a ui_component/*.xml file, it users the defaults from definition.xml. However, if your ui_component/*.xml file/tree, you can say

<price class="Some\Other\Class">
    <!-- some other configuration -->
</price>

and your changes in ui_component/*.xml will win.

  • I used wrong directory for my override, didn't I? Did I get you, Alan? – Roman Glushko Jul 15 '16 at 5:52
  • @RomanGlushko You used the wrong file. You don't want definition.xml, you want your changes in the specific grid file. – Alan Storm Jul 15 '16 at 15:58
  • @AlanStorm - Putting a new form field component definition inside a <form> ui xml file (for example), results in a "this element is not expected" error. Could you clarify exactly where we can define a new form field type? Magento's documentation is less than helpful, as per usual. – koosa Sep 23 '16 at 5:36
  • @AlanStorm - I think I understand now. You can only modify pre-existing components. You cannot define a new form element type altogether, say "customtext" for example. – koosa Sep 23 '16 at 5:50
  • @koosa That sounds right -- possibly of interest, I've been diving deep on UI components lately over on my site. alanstorm.com/category/magento-2#magento_2_ui – Alan Storm Sep 23 '16 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.