New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move rendering of Order Attribution inputs fully to JS #44335
Conversation
Test Results SummaryCommit SHA: 9b25355
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
In the issue thread, @RistoNiinemets mentioned:
Do you mean to rename the element's name to plural with "s" at the end? I was thinking about it but couldn't decide ;) window.customElements.define( 'wc-order-attribution-input', class extends HTMLElement {
set values( values ) {
this.#internals.setFormValue( … );
}
} So, there would be just a single But, as |
Hi , @woocommerce/ventures Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
bd0fca0
to
eceab9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 Thanks @tomalec, this works as described.
I noticed one small typo.
plugins/woocommerce/client/legacy/js/frontend/order-attribution.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Justin Palmer <228780+layoutd@users.noreply.github.com>
- Define custom element for order-attribution to move DOM manipulations to JS only. To support multiple checkout & register forms on the same page. Co-authored-by: Justin Palmer <228780+layoutd@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com>
This is a bit more revolutionary version of #44333, that aims to make the OA more resilient to bugs like #44159
Submission Review Guidelines:
Changes proposed in this Pull Request:
to move DOM manipulations to JS only.
To support multiple checkout & register forms on the same page.
Addresses #44159
Before, the responsibility to manipulate DOM in regards to Order Attribution data for the classic forms was spread between PHP and JS. This was IMHO making the code harder to maintain, as a developer needs to jump between files to understand the logic. It also occurred to be pretty bug-prone, as we have at least two reports on some mismatch, where the JS is in place expecting the inputs to be rendered by PHP, but for some reason, they are not fully rendered.
input[name="${params.prefix}${key}"]
).value = value; #44353This PR moves the logic completely to JS. The only thing that PHP does is to declaratively stamp a single HTML element (
<wc-order-attribution-inputs>
) in respective form.Then, the element itself (defined in JS) would populate itself with complete form data.
Such change also adds the support for more complex use cases when there are multiple checkout and/or registration forms on the same page.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Fix the bugs
Multiple forms
document.querySelectorAll( `wc-order-attribution-inputs` )
Changelog entry
Significance
Type
Message
Move the rendering of Order Attribution inputs fully to JS. Support multiple instances on the same page.
Comment