form->fill([]); } public function form(Form $form): Form { $currencyOptions = collect(CurrencyAccessor::getAllCurrencyOptions())->mapWithKeys(static fn ($currency) => [ $currency => Blade::render(""), ]); return $form ->schema([ Select::make('type') ->options(AccountTypeEnum::class) ->native(false) ->disabled(fn () => $this->showingConfirmation) ->required() ->placeholder('What would you like to add') ->prefixIcon('heroicon-s-credit-card') ->label('Account type') ->live(onBlur: true), TextInput::make('name') ->placeholder('i.e. John Doe Credit Card') ->label('Account name') ->reactive() ->readOnly($this->showingConfirmation) ->required() ->live(onBlur: true), Group::make([ TextInput::make('balance') ->placeholder('0.00') ->label('Balance') ->dehydrated() ->money(static fn (Get $get) => $get('currency')) ->readOnly($this->showingConfirmation) ->required() ->live(onBlur: true) ->columnSpan([ 'default' => 8, 'sm' => 9, ]) ->extraAttributes([ 'class' => 'balance-input', ]), Select::make('currency') ->options($currencyOptions) ->optionsLimit(200) ->default(CurrencyAccessor::getDefaultCurrency()) ->native(false) ->preload() ->disabled(fn () => $this->showingConfirmation) ->searchable() ->searchLabels(false) ->searchDebounce(0) ->getSearchResultsUsing( fn (string $search) => collect(CurrencyAccessor::getCurrrencyOptions($search))->mapWithKeys(static fn ($currency) => [ $currency => Blade::render(""), ]) ) ->getOptionLabelUsing( fn ($value) => Blade::render("") ) ->allowHtml() ->searchPrompt('Search...') ->placeholder('USD') ->afterStateUpdated(static function (Set $set, $state, $old, Get $get) { $balance = CurrencyConverter::convertAndSet($state, $old, $get('balance')); if ($balance !== null) { $set('balance', $balance); } }) ->label('Currency') ->hiddenLabel() ->required() ->live(onBlur: true) ->columnSpan([ 'default' => 4, 'sm' => 3, ]) ->extraAttributes([ 'class' => 'currency-select', ]), ])->columns([ 'default' => 12, ])->extraAttributes([ 'class' => '[&>div]:items-end [&>div]:gap-0 currency-container', ]), ]); } public function render(): View { return view('accounts.create-account-form'); } public function updatedInteractsWithForms(string $statePath): void { $this->resetErrorBag($statePath); } public function toggleConfirming(): void { if ($this->showingConfirmation) { $this->form->reset(); $this->showingConfirmation = false; } else { $this->form->validate(); $this->showingConfirmation = true; } } }