TextColumn and TextInputColumn for the same property

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.
Solution:
The issue is that both columns have the same name. They must be unique. Give the TextColumn a different name and use getStateUsing()
Jump to solution
6 Replies
SH0_T
SH0_TOP3w ago
Images:
No description
No description
SH0_T
SH0_TOP3w ago
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(),
]),
]);
}
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;
}
}
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;
}
}
Solution
Dennis Koch
Dennis Koch3w ago
The issue is that both columns have the same name. They must be unique. Give the TextColumn a different name and use getStateUsing()
SH0_T
SH0_TOP3w ago
Thank you very much! I completely overlooked this in the docs. Is mark solution broken? right click -> mark solution -> Error: The appliciation did not respond.
Dennis Koch
Dennis Koch3w ago
Maybe the server is down 🤔
SH0_T
SH0_TOP3w ago
I think so, Will try it in a few hours again

Did you find this page helpful?