0

I have used Address field module for storing user address. Also I have used Customer Profile Type UI for adding customer profile. I have added customer profile field in the user page by adding customer profile field in account settings. In the customer profile type I have added address field, name field and etc..

In my case Check box will be available on clicking checkbox an ajax callback happens which renders the customer profile form which has address field and name, for now no problem occurs. In address field all country are available and showing site default county as default one. If user change the country ajax call happens and address field hides. Please help me.

10
  • When change to any country or specified countries?
    – Yuseferi
    Commented Nov 23, 2015 at 5:46
  • For all country it hides. If I have not changed the country and all fields, appear and saves. For the second time when I change country, it works fine. @zhilevan
    – user50991
    Commented Nov 23, 2015 at 5:50
  • it seems some scripts hide it,can you change your theme to default themes and try it?
    – Yuseferi
    Commented Nov 23, 2015 at 5:53
  • @zhilevan I am using bootstrap theme and changed the theme to Bartik still I am facing the issue.
    – user50991
    Commented Nov 23, 2015 at 6:03
  • I have a solution that you can fix it with js, but before it try to find out the main reason of this issue, in firebug in loaded js search for class or id of zip code html element and see who hide it?
    – Yuseferi
    Commented Nov 23, 2015 at 6:22

3 Answers 3

2

It works as designed. For some countries there is no need to enter ZIP code.

You can change this behavior by implementing this alter in your custom module:

/**
 * Allows modules to alter the predefined address formats.
 *
 * @param $address_formats
 *   The array of all predefined address formats.
 *
 * @see addressfield_get_address_format()
 */
function hook_addressfield_address_formats_alter(&$address_formats) {
  $address_formats['AF']['required_fields'] = array('postal_code');
  $address_formats['AF']['used_fields'] = array('administrative_area', 'postal_code');
}

Change required_fields and used_fields as desired. More code you can find in this file:

addressfield/addressfield.address_formats.inc
2
  • Still postal address field is hiding. when country changed entire field is hidden
    – user50991
    Commented Nov 23, 2015 at 4:12
  • You should change country as well. 'AF' to whatever country you need.
    – paravibe
    Commented Nov 23, 2015 at 14:41
0

It is possible by using these modules :

Conditional Fields

Define dependencies between fields based on their states and values.

Conditional Fields for Drupal 7 is an user interface to the new States API, plus the ability to modify fields appearance and behavior on certain conditions when viewing content

Field Conditional States

With the Field Conditional State module you can change the state of any supported fields form element depending on the content of other fields. This is done by providing an UI for Drupal's States API. All the changes made to a form by FCS (Field Conditional States) utilize only the States API and therefore are clientside only

0

Finding the main reason of this issue need some debuging but I as you wanted I suggest you a solution that bypass this issue:
In your Custom JS file handle it by custom JS,provide a change handler and on change if country JQUERY event, show Zip Code field. something like

First Try it Firebug Console and when worked put it JS file
< Change The page class and element ID according your HTML elemets >

(function($){
$('.page-review #edit-customer-profile-shipping-commerce-customer-address-und-0-country').on('change',function(){
     $('.page-review #edit-customer-profile-shipping-commerce-customer-address-und-0-postal-code--2').show();
});
})(jQuery);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.