Posted by Limay on April 2, 2010 at 1:44pm
7 followers
Jump to:
| Project: | Ubercart Payment Method Adjustments |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
On uc_pma.js there is an error with the radio buttons Jquery selector. The subtotal don´t update because the event don´t fire.
On line 7:
$("input:radio[@name='panes[payment][payment_method]']").click(
you need to escape the "[]" symbols:
$("input:radio[@name='panes\\[payment\\]\\[payment_method\\]']").click(
Comments
#1
I can't reproduce this using the default version of JQuery included with Drupal 6, in fact if I make the change you propose then the selector no longer works. Are you running jquery_update?
#2
I have the same issue. In my Drupal it works with this code:
$("input:radio[@name='panes\\[payment\\]\\[payment_method\\]']").click(
(only escaping the [] symbols within simple cuotes)
And yes, i have jquery update module enabled.
#3
I have the latest jQuery update running at 1.3.2. Adding the slashes to the selector fixed this issue for me. Thanks!
#4
So we need to find a way of making this work whether jquery_update is installed or not...
#5
Hi, I meet this issue yesterday. Since jQuery 1.3.2 all weird characters used in ID, NAME or CLASS attributtes have to be escaped by double backslash "\\" as Limay and Carlitus mentioned before.
I suggest something like this:
// What is current jQuery version?
var jq_version_int = parseInt(jQuery.fn.jquery.replace(/\./gi, ''));
// Escape weird characters for jQuery 1.3.2+
function jq_escape_id(id) {
if (jq_version_int > 126) {
return id.replace(/([:|\.\[\]])/g, '\\$1');
}
return id;
}
$("input:radio[@name='" + jq_escape_id('panes[payment][payment_method]') + "']").click(function() {
//... your code ..
});
You can play around with example which I provided at jsFiddle.net
Another solution is selecting RADIOS using theirs parent element with some stable ID (I mean ID which is not dependant on some theme tweaks and doesn't include weird characters) ...
I think this could play pretty nice:
$("#payment-pane input:radio").click(function() {//... your code ..
});
#6
$("#payment-pane input:radio")looks much simpler but there could be a case where a specific payment method uses another set of radio buttons in its own option form.What about using that method, but with a wildcard attribute:
$('#payment-pane input:radio[name*="payment_method"]')?#7
ok it could work if some of these specific payment methods radio buttons sets do not include that string in theirs name...
Another alternative could be injecting some unique CSS class or ID in hook_form_alter() to panes[payment][payment_method] radios. So we can select them easily...
Oh wait, and what about this?
$('#payment-pane input:radio[id^="edit-panes-payment-payment-method-"]').each(function() {//... your code here ..
});
ID strings are "weird characters free" so it allows us to be more specific and it will work in all jQuery versions...
#8
Anyway I suggest some more changes.
1) Implement drupal.behaviors + context instead of document.ready (I know that in UC developers don't implement it, but they should, it is right way how to do it in Drupal - especially with jQuery 1.2.6, without $.live() support). Also adding uc-pma-processed class should be considered to avoid duplicate bindings.
2) Make URL in JS more flexible - if you write URL in the way like base_path + 'some/url' it can't be modified by url_rewrite_inbound and outbound so it will not work on sites which uses modules which rewrites URL like 118n. The implementation of solution this is relatively easy, I suggest this solution to UC developers, year ago and they implement it in UC2.1 or 2.2 I believe.
3) Change name of internal functions in the module to respect of Drupal Standards. There are some special cases like dpm() or dvm() etc. from devel module, but I think that payment_method_adjustment_description() or _payment_method_adjustment() aren't privileged in any aspect...
4) Initialize all variables. (yes I'm pedantic ;-) )
Output from php-initialized tool
Uninitialized variable $items on line 84Uninitialized variable $rows on line 118
Uninitialized variable $rows on line 127
Uninitialized variable $description on line 167
Uninitialized variable $ret on line 187
Should I post separate issues for all that things?
#9
I don't think we need separate issues, I would just repost them under a single new "code cleanup" issue so we can concentrate on the jQuery bug here. And as well as posting issues, if you want to provide patches that would be even more useful ;) Otherwise I'll try to find some time to spend on fixing up this module in the next week or so.
#10
I just run into this problem. First time I'm using uc_pma with jquery_update in the same site.
I was searching for AJAX problems in uc_pma and It took 2 days to find this post but here I am.
I tried the patch longwave gave (http://drupal.org/node/992630) but with no luck. Have you succeded in finding a solution to this?