I need to show/hide a magento input field (so NOT a custom field) based on the selected country in the shipping address form. Shipping address form is in two places: the customer account address book and the checkout > new shipping address popup page. So. for instance, the company field needs to be hidden for all countries except US, while for US country not only the company field must be visible but it needs to be required as well.
On the customer account form, my code works. I created a mixin for the customer-address-validation
and added my code there:
requirejs-config.js
var config = {
config: {
mixins: {
addressValidation: {
'Vendor_Module/js/view/customer-address-validation-mixin': true
},
'Magento_Customer/js/addressValidation': {
'Vendor_Module/js/view/customer-address-validation-mixin': true
}
}
}
};
customer-address-validation-mixin.js
[...]
if(countryId == countryCode) {
this.companyInput.addClass('required-entry').attr('aria-required', true);
this.companyContainer.addClass('required').show();
} else {
this.companyInput.removeClass('required-entry').removeAttr('aria-required');
this.companyContainer.removeClass('required').hide();
}
[...]
How can I apply the same code to the checkout shipping address form?