Reactive ->live() not updating ->helperText and/or ->label() values

Title says it all - my code below, am I missing something blindingly obvious? I'd expect the title and helper text to update on the title field when the type field changes.
return $form
->schema([
Select::make('type')
->options(MenuItemTypes::class)
->live()
->disabled(fn (?string $operation) => $operation === 'edit')
->required()
->helperText('Either add a single entry like a recipe or add mulitple options to choose from. This option can\'t be changed once set'),

Toggle::make('is_active')
->default(0),

TextInput::make('title')
->label(fn (Get $get): string => ($get('type') == MenuItemTypes::OPTIONS) ? 'Options title' : 'Title')
->helperText(fn(Get $get): ?string => ($get('type') == MenuItemTypes::OPTIONS) ? 'e.g. Choose 3 from the following options' : '')
->required()
->maxLength(255),
]);
return $form
->schema([
Select::make('type')
->options(MenuItemTypes::class)
->live()
->disabled(fn (?string $operation) => $operation === 'edit')
->required()
->helperText('Either add a single entry like a recipe or add mulitple options to choose from. This option can\'t be changed once set'),

Toggle::make('is_active')
->default(0),

TextInput::make('title')
->label(fn (Get $get): string => ($get('type') == MenuItemTypes::OPTIONS) ? 'Options title' : 'Title')
->helperText(fn(Get $get): ?string => ($get('type') == MenuItemTypes::OPTIONS) ? 'e.g. Choose 3 from the following options' : '')
->required()
->maxLength(255),
]);
Solution:
the values of the select single,options so change the condetion to ...
Jump to solution
12 Replies
Lara Zeus
Lara Zeus5mo ago
do you get this too? seems type dosne have a property or mapped to a state path
No description
Lara Zeus
Lara Zeus5mo ago
Blackpig
Blackpig5mo ago
Nope, I have no errors in the console
Lara Zeus
Lara Zeus5mo ago
are you in a resource or a custom page? I tested in custom page
Blackpig
Blackpig5mo ago
I'm in a resource (it's quite deeply nested) My Enum
<?php

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;

enum MenuItemTypes: string implements HasLabel
{
case SINGLE = 'single';
case OPTIONS = 'options';


public function getLabel(): ?string
{
return match ($this) {
self::SINGLE => 'Single entry',
self::OPTIONS => 'Menu options',
default => '',
};
}
}
<?php

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;

enum MenuItemTypes: string implements HasLabel
{
case SINGLE = 'single';
case OPTIONS = 'options';


public function getLabel(): ?string
{
return match ($this) {
self::SINGLE => 'Single entry',
self::OPTIONS => 'Menu options',
default => '',
};
}
}
Lara Zeus
Lara Zeus5mo ago
try dd, see what is the data,
->label(fn (Get $get): string => dd(get('*'))
->label(fn (Get $get): string => dd(get('*'))
Blackpig
Blackpig5mo ago
I've tried in the top level resource with the same result - so I don't believe it's to do with the nested respources
array:3 [▼ // app/Filament/Resources/MenuItemResource.php:48
0 => null
1 => false
2 => null
]
array:3 [▼ // app/Filament/Resources/MenuItemResource.php:48
0 => null
1 => false
2 => null
]
but that then prevents any further execution
Blackpig
Blackpig5mo ago
Pushing the output to ray the value is updating
No description
Solution
Lara Zeus
Lara Zeus5mo ago
the values of the select single,options so change the condetion to ->label(fn (Get $get): string => ($get('type') == MenuItemTypes::OPTIONS->value) ? 'Options title' : 'Title')
Lara Zeus
Lara Zeus5mo ago
get the keys of the selected item MenuItemTypes::OPTIONS->value
Lara Zeus
Lara Zeus5mo ago
Blackpig
Blackpig5mo ago
Thank you! I knew it was something stupid. Appreciate your help, karma++
Want results from more Discord servers?
Add your server
More Posts