Skip to content

Add MatrixStateCast and enhance Matrix validation#37

Merged
atmonshi merged 4 commits into4.xfrom
fix/validation-and-casts
Feb 6, 2026
Merged

Add MatrixStateCast and enhance Matrix validation#37
atmonshi merged 4 commits into4.xfrom
fix/validation-and-casts

Conversation

@Abdulmajeed-Jamaan
Copy link
Contributor

Introduces the MatrixStateCast class for custom state casting in matrix components. Updates Matrix.php to use the new state cast and improves validation logic for row and column selections, supporting both checkbox and radio modes.

Fixes #35

Introduces the MatrixStateCast class for custom state casting in matrix components. Updates Matrix.php to use the new state cast and improves validation logic for row and column selections, supporting both checkbox and radio modes.
@atmonshi
Copy link
Member

atmonshi commented Feb 1, 2026

thank you so much, so far working prefectly
one thing i noticed when I set the values (to mimick the edit senario)

->formatStateUsing(function () {
    return [
        'companies' => ['c'],
        'clients' => ['m' => true, 'p' => true],
    ];
})

still getting the error Array to string conversion

Added a PHPStan ignore comment above the protected $view property in the Matrix component to suppress static analysis warnings.
Appends the column key to the wire:key attribute to ensure unique keys for each input in the matrix-choice Blade component, preventing potential rendering issues with Livewire.
Modified the state casting logic in MatrixStateCast to retain original array keys when the state item is an array, instead of always appending values. This ensures that associative arrays are handled correctly during state transformation.
@atmonshi atmonshi merged commit 75b2501 into 4.x Feb 6, 2026
3 checks passed
@atmonshi atmonshi deleted the fix/validation-and-casts branch February 6, 2026 18:24
@atmonshi atmonshi restored the fix/validation-and-casts branch February 6, 2026 18:26
@Abdulmajeed-Jamaan Abdulmajeed-Jamaan deleted the fix/validation-and-casts branch February 6, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upon saving, The field is invalid

2 participants