Send an specific value using a dependent select

hey guys, i need a little help please, can't find a solution for this, i have a select:
Forms\Components\Select::make('email')
->label('Seleccione a quien desea enviar la notificación')
->options(function () use ($tenant) {
// Obtener los riders por el company_id del tenant
$riders = Rider::whereHas('companies', function ($query) use ($tenant) {
$query->where('companies.id', $tenant->id);
})->orderBy('name')->get();
// Construir el array de opciones para el Select
$options = ['all' => 'Enviar este mensaje a todos los clientes']; // Opción "todos"
foreach ($riders as $rider) {
$options[$rider->email] = $rider->name . ', RUT= ' . $rider->rut;
}
return $options;
})
->live()
->required(),
Forms\Components\Select::make('email')
->label('Seleccione a quien desea enviar la notificación')
->options(function () use ($tenant) {
// Obtener los riders por el company_id del tenant
$riders = Rider::whereHas('companies', function ($query) use ($tenant) {
$query->where('companies.id', $tenant->id);
})->orderBy('name')->get();
// Construir el array de opciones para el Select
$options = ['all' => 'Enviar este mensaje a todos los clientes']; // Opción "todos"
foreach ($riders as $rider) {
$options[$rider->email] = $rider->name . ', RUT= ' . $rider->rut;
}
return $options;
})
->live()
->required(),
here, if i select a option with the value
all
all
i mean, this line
$options = ['all' => 'Enviar este mensaje a todos los clientes']; // Opción "todos"
$options = ['all' => 'Enviar este mensaje a todos los clientes']; // Opción "todos"
i need send a
value 1`` in this part:
value 1`` in this part:
Forms\Components\TextInput::make('forall') ->live() ->default(fn (Get $get) => $get('email') === 'all' ? 1 : 0),
however if i send a select with value email like
however if i send a select with value email like
[email protected]``` i need send the value 0. i try with that line in forall but this is not working for me... how can do this? Thank you!
3 Replies
TranceCode
TranceCodeOP10mo ago
any idea about this?
Tieme
Tieme10mo ago
Try afterStateUpdated on the select and Set the value on textinput forall
TranceCode
TranceCodeOP10mo ago
Thank you so much @Tieme, i update my code to this, and is working really good:
Forms\Components\Select::make('email')
->label('Seleccione a quien desea enviar la notificación')
->options(function () use ($tenant) {
// Obtener los riders por el company_id del tenant
$riders = Rider::whereHas('companies', function ($query) use ($tenant) {
$query->where('companies.id', $tenant->id);
})->orderBy('name')->get();
// Construir el array de opciones para el Select
$options = ['all' => 'Enviar este mensaje a todos los clientes']; // Opción "todos"
foreach ($riders as $rider) {
$options[$rider->email] = $rider->name . ', RUT= ' . $rider->rut;
}
return $options;
})
->live()
->afterStateUpdated(fn (Set $set, ?string $state) => $set('forall', $state === 'all' ? 1 : 0))
->required(),
Forms\Components\Select::make('email')
->label('Seleccione a quien desea enviar la notificación')
->options(function () use ($tenant) {
// Obtener los riders por el company_id del tenant
$riders = Rider::whereHas('companies', function ($query) use ($tenant) {
$query->where('companies.id', $tenant->id);
})->orderBy('name')->get();
// Construir el array de opciones para el Select
$options = ['all' => 'Enviar este mensaje a todos los clientes']; // Opción "todos"
foreach ($riders as $rider) {
$options[$rider->email] = $rider->name . ', RUT= ' . $rider->rut;
}
return $options;
})
->live()
->afterStateUpdated(fn (Set $set, ?string $state) => $set('forall', $state === 'all' ? 1 : 0))
->required(),
Forms\Components\TextInput::make('forall')
->label('For All')
->disabled()
->default('0'),
Forms\Components\TextInput::make('forall')
->label('For All')
->disabled()
->default('0'),
Want results from more Discord servers?
Add your server