Kitty
Problem with afterStateHydrated
In a custom page, I am trying to set my toggle buttons default value based on its dynamic options. The options are based on different field values.
I have tried both default() and afterStateHydrated(). Even though I can populate the options correctly, I can not access the fields options in either of those methods when the options are dependent on other fields. How can I fix this?
Assume: $get('dob') = '02/20/2022' and $get('prematurity_id') = '02/30/2022'
This correctly gets the options
Trying to set the default, but $component->getOptions() returns null
If I don't try to GET the value from other fields, this correctly sets the default
11 replies
Searchable & Required Select Bug
When using a select field with searchable and required in a Livewire custom page the required validation fails. Removing the searchable and it works. It also works fine in a resource panel.
Code
Forms\Components\Select::make('zipcode_id')
->relationship('zipcode', 'zipcode')
->label('Your Oregon Zipcode')
->required()
->searchable(),
In the custom page, I can search and it fills the field with the value but is still fails the required validation so doesn't save and I get the required error message.
File: https://github.com/griggsk/osp/blob/main/CreateChild.php
Line 92 is where the zip is
Console errors
When selecting:
- Uncaught TypeError: this.select is null
- Uncaught (in promise) TypeError: this.select is null
Any ideas on how to fix? Thanks3 replies
Repeater Relationship missing :condition
What I am trying to do: Not Create Empty Repeater Relationships
What I Tried: Using the :condition variable. HasOne components have a :condition variable on the ->relationship method that allows you to set the field as optional so that the form does not try to create the relationship with an empty value. But it seems the HasMany Repeater does not support this variable. What I would like help with: Q: Is this to be expected?
Q2: How can I make a repeater be optional?
Note: I would prefer to set default to 1 and not create empty relationships.
Example: Works
Example: Works
Forms\Components\Group::make()
->relationship(
'childFamilyIncome',
condition: fn (?array $state): bool => filled($state['family_income_id']),
)
->schema([
...
])
Example: Doesn't work. Error Unknown named parameter $condition
Forms\Components\Repeater::make('childEthnicities')
->relationship('childEthnicities',
condition: fn (?array $state): bool => filled($state['ethnicity_id']))
->label('Child Ethnicities')
->simple(
...
)
->defaultItems(1)
2 replies