MissingRulesException when validating Form objects with boolean properties in Volt components
#9884
Replies: 1 comment
-
|
@amoktar thanks for reporting! This is a duplicate of #9860 so I'm going to close this. I've also already submitted a PR #9876 to fix this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Livewire version
4.1.0
Laravel version
12.48.1
Which PHP version are you using?
PHP 8.2
What is the problem?
When using a Livewire Form object within a Volt component, calling
$this->form->validate()throws aMissingRulesExceptionif the form contains a boolean property that has been updated via wire:model. The error message states: "Missing [$rules/rules()] property/method on: [component-name]."The issue occurs because Livewire incorrectly tries to find validation rules on the parent Volt component instead of the Form object during the hydration/validation cycle.
Code snippets
Steps to Reproduce
1. Create a Livewire Form with validation rules including a boolean property
2. Create a Volt component that uses the Form object
3. Reproduce the error
form.remembertotrue)Livewire\Exceptions\MissingRulesException: Missing [$rules/rules()] property/method on: [pages.auth.login].Expected Behavior
The
$this->form->validate()call should validate theLoginFormobject using its#[Validate]attributes, regardless of the values of the form properties. The validation should succeed (or fail with field-specific errors if data is invalid), but should not throw aMissingRulesException.Actual Behavior
When
form.rememberis set totrueand the form is submitted, Livewire throws:This occurs at line 18 of the compiled Volt component when calling
$this->form->validate().Important:
form.rememberisfalseor not included in the wire:model binding, everything works correctlytrueand sent via HTTP requestLivewire\Volt\Volt::test()do NOT reproduce the error (tests pass)Why Tests Don't Reproduce the Error
The bug does not manifest in Livewire's test helpers (
Volt::test()orLivewire::test()). Tests pass even withremember=true:his indicates the bug is specifically in Livewire's JavaScript→PHP hydration layer when handling serialized component state from actual HTTP requests, not in the core validation logic itself.
Environment
Additional Context
Why This Matters
This is a critical bug for authentication flows using Volt components, as "remember me" functionality is a common requirement. Users cannot log in with "remember me" enabled.
Potential Root Cause
Based on the error message and behavior, it appears that when Livewire deserializes the component state from the JavaScript HTTP POST request, it incorrectly attempts to resolve validation rules on the parent Volt component instance instead of the nested
LoginFormobject when certain boolean properties are present in the updates.The validation rule resolution seems to be looking at
$this(the Volt component) instead of$this->form(the Form object) during the hydration process whenremember=trueis in the payload.Workaround
Until this is fixed, the temporary workarounds are:
rules()method to the Volt component (hacky but works):Related Information
#[Validate]attributesfalsetotrueFull Error Stack Trace
Request Payload (from Browser)
When the error occurs, the Livewire HTTP POST to
/livewire/updatecontains:{ "_token": "...", "components": [ { "snapshot": "{...}", "updates": { "form": { "email": "user@example.com", "password": "password", "remember": true // ← This boolean true triggers the bug } }, "calls": [ { "method": "login", "params": [] } ] } ] }Suggested Fix Area
The issue likely resides in one of these areas:
The bug specifically involves the interaction between:
This indicates the bug is specifically in Livewire's JavaScript→PHP hydration layer when handling serialized component state from actual HTTP requests, not in the core validation logic itself.
How do you expect it to work?
Authentication flow should work, and tests should reflect the error.
Thank you.
Please confirm (incomplete submissions will not be addressed)
Beta Was this translation helpful? Give feedback.
All reactions