I have multiple addresses in one form. The first province field in the page is updated by ajax call, but the second not.
This is because bug in javascript:
// BUG
// Load province select element onLoad
performProvinceAjax($('.addresses-country-field'));
// FIX
// Load province select element onLoad
$('.addresses-country-field', context).each( function(){
performProvinceAjax(this);
});
performProvinceAjax() function processes only one element, not array of them. So when you send array of objects to it as argument, only first element in array is processed.
But I suggest bigger rewrite. Please use ".address-processed" class and "content" variable in Drupal behaviors - it can cause conflicts when you need to 1) reapply Drupal behaviors and/or 2) apply them on a particular content of the page.
See my patch against HEAD which is your 1.x-dev as I suggest from the revision graph.
Comment | File | Size | Author |
---|---|---|---|
#9 | addresses.patch | 14.29 KB | jaxxed |
#6 | addresses.js_.gz | 952 bytes | jaxxed |
#1 | addresses.js_.patch | 1.02 KB | wojtha |
Comments
Comment #1
wojtha CreditAttribution: wojtha commentedDon't know why, but attached patch disappeared after submitting the issue. So another try..
Comment #2
ISPTraderChris CreditAttribution: ISPTraderChris commentedI have confirmed this issue -- when multiple addresses fields are present, the province field is transformed to a select box via javascript on the first field during page load, and not subsequent addresses fields. I can also confirm that the above patch fixes this problem.
Comment #3
AlexisWilke CreditAttribution: AlexisWilke commentedISPTraderChris,
Thank you. I checked in the patch. Makes sense. 8-)
Alexis
Comment #5
jaxxed CreditAttribution: jaxxed commentedThis code doesn't allow for form theming using the drupal theme, if the elements are rearranged at all. The method of finding a country from .parent().siblings().child() is very unreliable.
If we can get a class into the parent address, and assume/allow any theming of the form to keep the class as a parent to any individual address set, then we can run the same operation but from the address parent.
Optimally it would be best to add an address type object with all of the methods, instead of keeping them in the Drupal.behaviour.
I will work on something for this.
Comment #6
jaxxed CreditAttribution: jaxxed commentedAttached is an in progress transition of the address.js, which doesn't rely on .parent().sibling().children().
Note that it requires a parent class of .addresses.form on an individual set of addresses.
@TODO
- finish writing it (it ain't finished)
- address object needs to take the first province and country fields found (in case of whacky implementation)
- exceptions
This in progress but feel free to comment/suggest something.
Comment #7
AlexisWilke CreditAttribution: AlexisWilke commentedCould I ask you to provide a patch as well? (diff -du org new)
Comment #8
jaxxed CreditAttribution: jaxxed commentedAlex: I will provide a patch, I am still working on it.
I have a refactored js implementation, and a related modification to the _process hook for the element. I think that this implementation is a bit better for best practices, and normal conventions.
Address.js:
hook_process:
I will post a patch by the end of the day.
Comment #9
jaxxed CreditAttribution: jaxxed commentedAlexis: Here is a patch of my running version.
Note that I had to include a php5.1 compatibility method for the the missing JSON library.
I didn't realize that Drp7 won't get an address module, so I likely overcoded the JS implementation. I wrote it so that it can be extended, which now I realize it likely won't be.
I had to change:
Things to do:
- dammit, I forgot to remove the class="text" when recreating the new fields
Comment #10
AlexisWilke CreditAttribution: AlexisWilke commentedThat looks pretty good already. I guess I'll need to find some time to test and check that in. It's a bit big so I better do that!
Thank you.
Alexis Wilke