Setting value of Select field with Boolean value options does not work.
Using
That does not work, but using a Radio component instead with the same method does work:
Am I doing something wrong here? How do I get this to work using the Select component?
afterStateUpdated()
to set the value of another field, which is a Select component that has Boolean options does not work.
Example:
Forms\Components\Select::make('code')
->label('Code')
->options(Currency::getCurrencyCodes())
->searchable()
->reactive()
->afterStateUpdated(static function (callable $set, $state) {
$code = $state;
$symbol_first = config("money.{$code}.symbol_first");
$set('symbol_first', $symbol_first);
})
->required(),
Forms\Components\Select::make('symbol_first')
->label('Symbol Position')
->options([
true => 'Before Amount',
false => 'After Amount',
])
->required(),
Forms\Components\Select::make('code')
->label('Code')
->options(Currency::getCurrencyCodes())
->searchable()
->reactive()
->afterStateUpdated(static function (callable $set, $state) {
$code = $state;
$symbol_first = config("money.{$code}.symbol_first");
$set('symbol_first', $symbol_first);
})
->required(),
Forms\Components\Select::make('symbol_first')
->label('Symbol Position')
->options([
true => 'Before Amount',
false => 'After Amount',
])
->required(),
Forms\Components\Select::make('code')
->label('Code')
->options(Currency::getCurrencyCodes())
->searchable()
->reactive()
->afterStateUpdated(static function (callable $set, $state) {
$code = $state;
$symbol_first = config("money.{$code}.symbol_first");
$set('symbol_first', $symbol_first);
})
->required(),
Forms\Components\Radio::make('symbol_first')
->label('Symbol Position')
->options([
true => 'Before Amount',
false => 'After Amount',
])
->required(),
Forms\Components\Select::make('code')
->label('Code')
->options(Currency::getCurrencyCodes())
->searchable()
->reactive()
->afterStateUpdated(static function (callable $set, $state) {
$code = $state;
$symbol_first = config("money.{$code}.symbol_first");
$set('symbol_first', $symbol_first);
})
->required(),
Forms\Components\Radio::make('symbol_first')
->label('Symbol Position')
->options([
true => 'Before Amount',
false => 'After Amount',
])
->required(),
1 Reply
I guess I have to do something like this instead:
So nevermind.
Forms\Components\Select::make('code')
->label('Code')
->options(Currency::getCurrencyCodes())
->searchable()
->reactive()
->afterStateUpdated(static function (callable $set, $state) {
$code = $state;
$symbol_first = config("money.{$code}.symbol_first");
if ($symbol_first === true) {
$symbol_first = '1';
else {
$symbol_first = '0';
}
$set('symbol_first', $symbol_first);
})
->required(),
Forms\Components\Select::make('symbol_first')
->label('Symbol Position')
->options([
'1' => 'Before Amount',
'0' => 'After Amount',
])
->required(),
Forms\Components\Select::make('code')
->label('Code')
->options(Currency::getCurrencyCodes())
->searchable()
->reactive()
->afterStateUpdated(static function (callable $set, $state) {
$code = $state;
$symbol_first = config("money.{$code}.symbol_first");
if ($symbol_first === true) {
$symbol_first = '1';
else {
$symbol_first = '0';
}
$set('symbol_first', $symbol_first);
})
->required(),
Forms\Components\Select::make('symbol_first')
->label('Symbol Position')
->options([
'1' => 'Before Amount',
'0' => 'After Amount',
])
->required(),