TextInput default() not work wit get()

I have two fields and this related. Forms\Components\Select::make('branch_id') ->label('Branch') ->live() ->relationship('branch', 'name', fn($query, $get) => $query->where('cluster_id', $get('cluster_id'))) ->afterStateUpdated(function (Set $set, ?string $state) { $set('idBranch', $state); // Add logging or debugging statements here Log::info("idBranch updated: $state"); }) ->searchable() ->preload(), Forms\Components\TextInput::make('code') ->required() ->readOnly() ->live() ->default(function (Get $get) { $branchName = Branch::query()->find($get('idBranch')); Log::info("idBranch updated: ".$get('idBranch')); $prefix = 'BPL' . $get('idBranch'); return GenerateCode::create(BudgetPlanner::class, 'code', $prefix); }) ->maxLength(255), but $get('idBranch') or $get('id_branch') not calling after branch_id is selected.
1 Reply
Jr.Pikong
Jr.PikongOP12mo ago
so for this solution, I set default value from the afterStateUpdated Forms\Components\Select::make('branch_id') ->label('Branch') ->live() ->relationship('branch', 'name', fn($query, $get) => $query->where('cluster_id', $get('cluster_id'))) ->afterStateUpdated(function (Set $set, ?string $state) { $branchName = Branch::query()->find($state); $prefix = 'BPL/' . $branchName->name; $set('code', GenerateCode::create(BudgetPlanner::class, 'code', $prefix)); }) ->searchable() ->preload(),
Want results from more Discord servers?
Add your server