#TextColumn and TextInputColumn for the same property

10 messages · Page 1 of 1 (latest)

warm saffron
#

Hey all & kind person who can help,

I have made a button that toggles the mode of the list view from "display" to "inline edit".
This is achieved by having a boolean that checks which of the two (TextColumn and TextInputColumn) it should hide.
Somehow this breaks the TextColumn, and the TextInputColumn works fine. But I need them both to work correctly.

The reason why im trying to achieve this is to be one button click away from a fast edit / delete screen instead of having it always that way.

Thx in advance.

tranquil streamBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

warm saffron
warm saffron
#

I forgot the code example:

public static function form(Form $form): Form
    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')
                    ->label('Name')
                    ->searchable()
                    ->sortable()
                    ->hidden(fn($livewire) => $livewire->isEditMode),
                TextInputColumn::make('name')
                    ->label('Name')
                    ->placeholder('Enter the name of the application')
                    ->rules(['required', 'max:255', 'unique:applications,name'])
                    ->hidden(fn($livewire) => !$livewire->isEditMode),
                TextColumn::make('created_at')
                    ->label('Created At')
                    ->sortable()
                    ->hidden(fn($livewire) => $livewire->isEditMode),
                TextColumn::make('updated_at')
                    ->label('Updated At')
                    ->sortable()
                    ->hidden(fn($livewire) => $livewire->isEditMode),
            ])
            ->defaultSort('name')
            ->persistSortInSession()
            ->filters([

            ])
            ->actions([
                EditAction::make()
                    ->hidden(fn($livewire) => $livewire->isEditMode),
                DeleteAction::make()
                    ->hidden(fn($livewire) => !$livewire->isEditMode),
            ])
            ->bulkActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }
#
class ListApplications extends ListRecords
{
    protected static string $resource = ApplicationResource::class;

    public bool $isEditMode = false;

    protected function getHeaderActions(): array
    {
        return [
            Action::make('toggleEdit')
                ->label(fn() => $this->isEditMode ? 'To Display Mode' : 'To Edit Mode')
                ->action('toggleEditMode'),
            CreateAction::make(),
        ];
    }

    public function toggleEditMode(): void
    {
        $this->isEditMode = !$this->isEditMode;
    }
}
vernal fiber
#

The issue is that both columns have the same name. They must be unique. Give the TextColumn a different name and use getStateUsing()

warm saffron
#

Thank you very much! I completely overlooked this in the docs.

warm saffron
vernal fiber
warm saffron
#

I think so, Will try it in a few hours again