Province field after page loaded not changed to drop-down select list. It shows as text input field.

But everything works when I open configure address field in CCK. I'm able to see both select lists for country and province under default value.

Same configuration works locally as require - province as select list and changed after country list selected.

CommentFileSizeAuthor
#17 addresses-6.x-1.12.patch610 bytesoknate
#9 gbf_c_4.jpg21.16 KBolmalex
#4 gbf_c_0.jpg148.31 KBolmalex
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AlexisWilke’s picture

There is indeed a case when the province is shown as a regular text field. I did not know when it would happen because CCK did not work right for me for a long time. Now it works, but I don't have much time to work on the module. I think also that the text field expects the abbreviated name only, which is not good. It should work with the full name too.

At least, I'll be able to test and see whether I can reach that state too.

Thank you for your report.
Alexis

olmalex’s picture

Alexis,

Thank you for quick replay. I'm happy that's the good news for you.

I need your advice or help how to change province to general select list. A few words to describe the case. Following modules are actived in Drupal - Addresses and Addresses - CCK. New content type has been created and using CCK added address field with required - country, province and none for rest.

It seems like the issue with widget when it has GET xmlhttprequest. I see error on load page and on select country click. Any idea what it might be?

Thanks in advance

AlexisWilke’s picture

Can you copy the error here? Is it a box appearing in your browser, an error in the error log or in your HTML server?

Thank you.
Alexis

olmalex’s picture

FileSize
148.31 KB

FF firebug shows the error. Please look into attached file. I don't have access to log files or server.

Thanks

AlexisWilke’s picture

This looks like a 301. You should not get a 301 on an AJAX call...

The function being called is in addresses.settings.inc around line 272.

function _addresses_province_ajax()

But I think that if you get a 301 the AJAX may have a "no-follow" policy (which would make sense) so that would be the problem.

Do you have Global Redirect maybe?

Thank you.
Alexis

olmalex’s picture

It's 301. I have function _addresses_province_ajax() in addresses.settings.inc line 241.

Yes, I have Global Redirect module 6.x-1.2 installed. How it might affect AJAX? What's your suggestion?

Thanks

olmalex’s picture

Having Global Redirect not explaining why the same configuration properly works on localhost and shows error on host.

AlexisWilke’s picture

The q=... will be redirected by Global Redirect. I'm not too sure why it would work on your localhost, unless you did not setup the clean URLs on the localhost?

To fix the problem we need to change the JavaScript code in addresses.js. First, if you don't mind, I'd like you to test this:

Change the current code:

    $.ajax({
      type:'GET',
      url:Drupal.settings.basePath,
      success:updateProvinceField,
      dataType:'json',
      data: {
        q:'addresses/province_ajax',
        country:$(countryElement).val(),
        field_id:provinceElement.attr('id'),
        field_name:provinceElement.attr('name'),
        passback:provinceElement.parent().attr('id'),
        province:provinceElement.val()
      }
    });

to this code, which uses the clean URL and no q parameter:

    $.ajax({
      type:'GET',
      url:Drupal.settings.basePath+'/addresses/province_ajax',
      success:updateProvinceField,
      dataType:'json',
      data: {
        country:$(countryElement).val(),
        field_id:provinceElement.attr('id'),
        field_name:provinceElement.attr('name'),
        passback:provinceElement.parent().attr('id'),
        province:provinceElement.val()
      }
    });

If that works, we need to check whether you have clean URLs turn ON or not and adjust the code accordingly.

Thank you.
Alexis

olmalex’s picture

FileSize
21.16 KB

On localhost I have clean URLs on. Here are the results after I've updated the code.
- Province still is text field. I'm not able to select.
- FF shows no error anywhere.
- IE7 shows runtime error on load page and after I attempt to select country (attached file).

Thanks

kulvik’s picture

Any news on this? I have the same problem here.

TheProducer’s picture

If anyone is still interested in why this isn't working, check your jQuery version.

It works with jQuery 1.2.6 . It failed when I tried the latest (1.6.1). The jQuery AJAX error callback claims "parsererror".

Anonymous’s picture

When I upgraded from 6.x-1.10 to 6.x-1.12 this bug showed up. My province fields were regular text fields.

I could tell Ajax was being called and there were no errors (along with a 200 response code) but the province did not transform into a select field with the correct options.

I really don't want to stay on 6.x-1.10 due to the security update :\

The page I use this on has two address fields. One has Address, City, State, ZIP. The other is just a country only field.

ratinakage’s picture

I get the same problem with version 1.12!

Any idea how it can be fixed....?

My JQuery is 1.2.6 by the way...

Anonymous’s picture

Yeah, forgot to mention the JQ was 1.2.6.

Eric At NRD’s picture

Version: 6.x-1.09 » 6.x-1.12

As with #12 above, I am seeing this problem with a CCK field after upgrading from 1.10 to 1.12. jQuery is version 1.2.6.

Looking at the console with Firebug, I can see the following GET (which returns with a 200):
/?q=addresses%2Fprovince_ajax&country=top_us&field_id=undefined&field_name=undefined&passback=undefined&province=undefined&language=en&attributes=%7B%7D

I'm guessing that "undefined" for field_id, field-name, passback, and province is at heart of the problem.

Looking at the resulting JSON, it contains quite a lot of "undefined" as well:

<label for="undefined">State / Province: </label><select id="undefined" name="undefined" class="addresses-province-field" ><option value="AL">Alabama</option>....
Eric At NRD’s picture

I just verified this same issue on a different Drupal 6 site (e.g. completely different server). As with above, it is address module 1.12 and jQuery 1.2.6. The AJAX call includes "undefined" for field_id and field_name, and the province is remaining a text input.

oknate’s picture

FileSize
610 bytes

I found a fix for this issue.

It seems that css classes need to be added to the input elements for the javascript to work, and they were not getting added for me when using the addresses cck field on a content type.

I found a fix: I could add code that adds the css classes to the end of the addresses_elements_process function, and this fixed the issue:

  // Add the extra fields to the element and return it.
  $element = array_merge($element, $extra);
 
  if (!empty($element['country'])) {
    $element['province']['#attributes']['class'] .= ' addresses-province-field';
    $element['country']['#attributes']['class'] .= ' addresses-country-field';

  } 
 
  return $element;

I've attached a patch.

AlexisWilke’s picture

That would make sense. 8-)

However, you patch lacks a few test. If you look closely in the addresses.settings.inc, both 'country' and 'province' need to be defined. Also, the '#attributes' or 'class' parameters may not be defined. This means doing a .= will generate notices (E_NOTICE errors.)

This being said, if it works for others, then we're on the right track!

Thank you.
Alexis

lhugg’s picture

I had the same problem, and 6.x-1.x-dev (I used the one dated 2011-Dec-12) seems to fix it. Thanks.

johnhorning’s picture

I'm having this problem as well, although it seems to be intermittent. I'll add more information when I can.
I'm using 6.x-1.12+7-dev