Skip to content

Conversation

@Flo0807
Copy link
Collaborator

@Flo0807 Flo0807 commented Jan 16, 2026

Filters

Core

  • Created Backpex.FilterValidation for changeset-based validation
    • build_changeset/3: builds schemaless changeset from URL params
    • valid_values/1: extracts only validated filter values
    • build_types/2: builds type map from filter configurations

New Filter Callbacks

  • Added type/1: specifies Ecto type for casting URL params
  • Added changeset/3: allows custom validation logic per filter
  • Added validate/2: public API for testing validation

Existing Filter Updates

  • Boolean Filter: validates selected keys exist in options/1
  • Select Filter: validates selected value exists in options/1
  • MultiSelect Filter: validates all selected values exist in options/1
  • Range Filter: validates date/number formats and that start <= end

LiveResource

  • Updated index.ex to use FilterValidation.build_changeset/3
  • Added @filter_form assign (Phoenix form from changeset)
  • Added @filter_values assign (only valid, casted values)
  • Invalid filters are not applied to queries: users see unfiltered results with inline errors

Ecto Adapter

  • Changed apply_filters/4 to apply_filters/3 (removed empty_filter_key parameter)
  • Filters now receive validated, casted values

Ordering & Pagination

  • Created lib/backpex/query_options_validation.ex for validating URL parameters
    • Uses Ecto changesets for integer validation (page, per_page)
    • Safe atom conversion for order_by/order_direction
    • Invalid values fall back to defaults instead of crashing
  • Invalid values silently fall back to defaults

@Flo0807 Flo0807 self-assigned this Jan 16, 2026
@Flo0807 Flo0807 marked this pull request as draft January 16, 2026 14:25
@Flo0807 Flo0807 added feature New feature breaking-change A breaking change labels Jan 16, 2026
@Flo0807 Flo0807 changed the title Refactor filters Refactor filtering, ordering and pagination Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change A breaking change feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants