fix(options): keep all option group panels mounted to preserve state#230
Merged
fix(options): keep all option group panels mounted to preserve state#230
Conversation
When the user switched between option group tabs in the product card,
all entered values reverted to defaults — even after clicking Save.
Cause: the panel rendered a single <section> with v-for over
activeGroup.options. Switching tabs swapped the array, Vue tore
down every ProductOptionField for the previous group and built
fresh ones for the new group. With them went:
- the local "value" ref of each field (visible "reset");
- the per-field hidden <input type="hidden"> that the MODX/ExtJS
BasicForm.getValues() collects on submit — so the POST silently
omitted everything that wasn't in the currently active tab.
That's why pre-saving didn't help: the form simply never sent those
fields, the server stored defaults, and on reload the user saw
defaults again.
Fix: render every group's panel up front and toggle visibility with
v-show instead of swapping activeGroup.options. Each
ProductOptionField is now built once, holds its local state across
tab switches, and its hidden input stays in the DOM so the form
collects values from every group at submit time.
Removes the now-unused activeGroup computed.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема
В карточке товара на вкладке «Опции товара», когда у товара несколько групп опций:
Это не визуальный баг — данные действительно теряются. Сохранение не помогает: значения неактивных табов вообще не доезжают на бэкенд.
Причина
Панель таба рендерила одну секцию с
v-forпо активной группе:Переключение
activeGroupId→ массивactiveGroup.optionsменяется → Vue разрушает всеProductOptionFieldстарого таба и создаёт новые для нового. Вместе с компонентом улетают:value = ref(...)каждого поля. Возврат на исходный таб → новый инстанс инициализируется снова изprops.option.value(исходное значение с бэкенда). Видимый «сброс».<input type="hidden">внутриProductOptionField(есть у всех типов кроме textfield/textarea). MODX/ExtJSBasicForm.getValues()собирает только те инпуты, что в DOM на момент сабмита. Поля неактивного таба в форму просто не попадают →_validatedна бэке для них пуст → сохраняются дефолты.Именно поэтому предварительное сохранение не спасает: POST уходит без этих полей, сервер кладёт дефолты, при следующей загрузке мы их и видим.
Фикс
Рендерим все группы сразу, прячем неактивные через
v-show. КаждыйProductOptionFieldсоздаётся один раз и живёт весь сеанс работы с карточкой:Также убран неиспользуемый
activeGroupcomputed.Чем платим
ProductOptionFieldсоздаются одномоментно при открытии вкладки. Если у товара 200+ опций в нескольких группах — лёгкое замедление первого рендера. На обычных товарах с десятками опций — незаметно.display: noneведут себя нормально.Test plan
single-groupветка продолжает работать как раньше.