Repository navigation
Fix "event is not a function" error on My Payment Methods page - #867
Conversation
|
Hi @agibson-godaddy , I’ve opened a framework fix for MWC-20379: #867. A missing pair of parentheses in the My Payment Methods CoffeeScript (.on 'click', event ->) throws “event is not a function” for any customer with a saved payment method. It affects every plugin bundling framework 6.2.4, and I confirmed it on Authorize.Net. It’s a one-liner plus the rebuilt dist. Two questions: should this go out as 6.2.5 with #864 or on its own, and who triggers the framework release? I’ve cut release/3.10.22 for Authorize.Net (#152) and will pin the new framework version in the story PR once it’s tagged. |
|
Tested this branch (7fae387) in WooCommerce Authorize.Net Gateway 3.10.22-dev.1, installed via a zip built from the branch’s own dist. On My Account > Payment Methods with a saved method, there is no event is not a function error in the console. The disabled “Add payment method” button no longer navigates while a method is being edited. Nickname save/cancel, set default, and delete (Cancel and OK) all work as before. Local PHPUnit errors identically (18 of 26) with and without this change on PHP 8.5 |
Summary
Fixes an uncaught
TypeError: event is not a functionthrown by the My Payment Methods handler whenever a customer has at least one saved payment method.Story: MWC-20379
Release: TBD
Details
In
sv-wc-payment-gateway-my-payment-methods.coffee, the click handler for the "Add payment method" button was written as.on 'click', event ->. Without parentheses, CoffeeScript compiles this to.on('click', event(function() {...})), a call towindow.event, which isn't a function. The constructor throws at that line, so the handler never finishes setting up and the guard that stops a disabled "Add payment method" button from navigating is never registered.The fix adds the missing parentheses:
.on 'click', ( event ) ->. The thin arrow is kept because the body relies on$( this )being the clicked button. Thedistasset and source map are rebuilt.The error only appears when a saved method exists, because WooCommerce only renders the payment methods table then. Other framework-based gateways bundling an affected version are likely affected too.
UI Changes
None.
QA
Setup
Steps
event is not a functionerror is loggedBefore merge