From 98501c1c26f4e34f12006e365309d25a16de8eec Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Tue, 23 Dec 2025 15:30:09 +0300 Subject: [PATCH] refactor(products): extract Order Item Select2 to reusable module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved order item selection logic from order_form.html to select2-product-search.js for better code reusability and maintainability. Changes: - Extended select2-product-search.js with initOrderItemSelect2() function (~87 lines) - Wraps initProductSelect2 for order item context - Handles product/kit selection and form field updates - Manages custom price indicators - Supports data-ajax-url attribute for URL configuration - Updated order_form.html: - Added data-ajax-url to order item select elements - Removed inline initOrderItemSelect2 function (~73 lines) - Updated dependency check to use initOrderItemSelect2 Benefits: - No code duplication - reuses existing initProductSelect2 - Cleaner template (79 lines removed) - Consistent with existing patterns - Easy to maintain in one place πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../orders/templates/orders/order_form.html | 89 +++---------------- .../products/js/select2-product-search.js | 87 ++++++++++++++++++ 2 files changed, 97 insertions(+), 79 deletions(-) diff --git a/myproject/orders/templates/orders/order_form.html b/myproject/orders/templates/orders/order_form.html index f5cd303..d60d2f4 100644 --- a/myproject/orders/templates/orders/order_form.html +++ b/myproject/orders/templates/orders/order_form.html @@ -244,7 +244,9 @@
- {% if item_form.instance.product %}