Conversation
…arent form phx-change This commit fixes an issue where combobox search inputs would incorrectly trigger parent form phx-change events during typing, when only selection changes should trigger form updates. ## Changes ### JavaScript (assets/js/hooks/combobox.js) - Add `notifyFormChange()` method to dispatch DOM input events on hidden inputs - Make `stopPropagation()` conditional: only stop in frontend mode, not async mode - Call `notifyFormChange()` in `addSelection()` and `removeSelection()` to notify parent forms ### Elixir Component (lib/prima/combobox.ex) - Add `phx-update="ignore"` to search input to preserve value across LiveView updates - Prevents search input from being reset when parent form phx-change triggers updates ### LiveView (lib/prima_web/live/fixtures_live.ex) - Update `form_changed` handler to ignore events from `_search` fields - Only count actual selection changes (from hidden value inputs) ### Tests (test/wallaby/prima_web/combobox_form_integration_test.exs) - Add `assert_form_change_count/3` helper for cleaner assertions - Add test for async combobox form integration behavior - Add test for search input value persistence after form updates - Create new async combobox form change fixture ### Documentation Updates - Replace `prima-search` with `phx-change` in async combobox examples - Update fixtures to use standard Phoenix LiveView patterns ## Why This Works 1. **Search input filtering**: LiveView handler checks if `_target` ends with `_search` and ignores those events (typing doesn't trigger form change) 2. **Selection notification**: When selection changes, `notifyFormChange()` dispatches a DOM input event on the hidden value input, which triggers form phx-change 3. **Async mode support**: `stopPropagation()` only applies in frontend mode, allowing async comboboxes to still send their search events to the server 4. **Value persistence**: `phx-update="ignore"` on search input prevents LiveView from resetting the displayed value during re-renders ## Test Coverage - ✅ Frontend combobox: search doesn't trigger form change, selection does - ✅ Async combobox: search doesn't trigger form change, selection does - ✅ Search input value persists after selection when form updates - ✅ Multiple selection changes properly increment form change counter 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Merged `combobox_selection_change_fixture` and `combobox_form_change_fixture` into a single `combobox_change_fixture` that tests both combobox-level and form-level phx-change events together. ## Changes - Created unified fixture with one combobox inside a form - Combobox has `phx-change="selection_changed"` (component-level) - Form has `phx-change="form_changed"` (form-level) - Both selection display and form change counter visible in same fixture - Updated all test references to use new IDs: `#change-combobox`, `#change-options` - Replaced two routes with single `/fixtures/combobox-change` route ## Benefits - Simpler test infrastructure (1 fixture instead of 2) - Tests both behaviors together in realistic scenario - Demonstrates that both event types work correctly when combined - Easier to maintain with fewer files All 7 tests passing with unified fixture. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Corrected the documentation to reflect the actual implementation: - Async mode is triggered by adding `phx-change` to the search input - The `getMode()` function checks for `phx-change` attribute on search input - All examples and attribute documentation now correctly use `phx-change` The previous documentation incorrectly referenced `prima-search` which was from an earlier iteration that was never implemented. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Adds documentation explaining that combobox triggers parent form phx-change only on selection changes, not during search input typing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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.
No description provided.