0

enter image description here

I want the VAT number filed on to present when i click the user to zero vat customer group.If click any other group i dont want to show the vat field. Anyone has any idea how to fix this.

/private/var/www/html/magento2/vendor/magento/module-customer/view/base/ui_component/customer_form.xml

this is the core file for this

0

Hide Tax/Vat Number Field from customer admin form based on Customer Group.

You can hide Tax/Vat Number field and only show based on specific selected group like 1

You can change group value as you want show/hide on Tax/Vat Number field.

Follow below steps:

File path: magento/app/code/Vendor/CustomerForm/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_CustomerForm',
    __DIR__
);

File path: magento/app/code/Vendor/CustomerForm/etc/module.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_CustomerForm" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Customer"/>
        </sequence>
    </module>
</config>

File path: magento/app/code/Vendor/CustomerForm/view/adminhtml/ui_component/customer_form.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">    
    <fieldset name="customer">
        <settings>
            <label translate="true">Account Information</label>
        </settings>
        <container name="container_group" component="Magento_Ui/js/form/components/group" sortOrder="20">
            <argument name="data" xsi:type="array">
                <item name="type" xsi:type="string">group</item>
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string" translate="true">Group</item>
                    <item name="required" xsi:type="boolean">true</item>
                    <item name="dataScope" xsi:type="boolean">false</item>
                    <item name="validateWholeGroup" xsi:type="boolean">true</item>
                </item>
            </argument>
            <field name="group_id" formElement="select">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="fieldGroup" xsi:type="string">group_id</item>
                        <item name="component" xsi:type="string">Vendor_CustomerForm/js/customer</item>
                        <item name="source" xsi:type="string">customer</item>
                    </item>
                </argument>
                <settings>
                    <dataType>number</dataType>
                </settings>
            </field>
        </container>
        <field name="taxvat" formElement="input">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="source" xsi:type="string">customer</item>
            </item>
        </argument>
        <settings>
            <validation>
                <rule name="required-entry" xsi:type="boolean">true</rule>
            </validation>
            <dataType>text</dataType>
            <visible>true</visible>
        </settings>
    </field>
    </fieldset>
</form>

File path: magento/app/code/Vendor/CustomerForm/view/adminhtml/web/js/customer.js

define([
    'underscore',
    'uiRegistry',
    'Magento_Ui/js/form/element/select',
    'Magento_Ui/js/modal/modal'
], function (_, uiRegistry, select, modal) {
    'use strict';

    return select.extend({
        onUpdate: function (value) {

            var taxvat = uiRegistry.get('index = taxvat');
            if(value == 1) {
                taxvat.show();
            } else {
                taxvat.hide();
            }
            return this._super();
        },
    });
});

Try this above code and let me know if any issue.

Hope it help!

  • I want the VAT number filed on to present when i click the user to zero vat customer group. How can i do that @kirti nariya – jibin george Nov 21 '18 at 11:55
  • It didnt work it just removes the Tax/Vat filed from all Groups. I wanted to show the field only when i chose Group = zero vat customer group – jibin george Nov 21 '18 at 12:03
  • @Jibin george you can check this link for hide / show filed in admin magento.stackexchange.com/questions/45819/… – Kirti Nariya Nov 21 '18 at 13:02
  • That page didn't help much, I need to change the ui_component. at the the code you have provided here i tried that and that only hides the field for all groups i need to hide it just for one specific group – jibin george Nov 21 '18 at 13:30
  • @jibingeorge Please check my update my answer. – Kirti Nariya Nov 26 '18 at 16:39

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.