Joshua
Joshua
Explore posts from servers
FFilament
Created by Joshua on 12/26/2024 in #❓┊help
TextArea value does not work in a normal resource form
I feel like I'm missing something very obvious, and I've looked around the discords to try and find previous discussions about this as well as the textarea docs page. I'm just trying to use a textarea instead of a textinput in the formbuilder, no custom pages and nothing fancy. However the textarea boxes in particular don't work with default() or formatStateUsing() and setting it manually. I'm a bit confused because simply swapping textarea for textinput makes the text display correctly. The issue seems very specific to textareas. I'll attach a snippet from an example resource just to show, but I ahve this issue across like 8 different resources with a few different options used. This specific example doesn't have default or formatStateUsing but I've tried both, and really neither should be necessary. The field on the Mods model is "description" so it should be inhereted like every other field.
<?php

namespace Pterodactyl\Filament\Resources;

use Filament\Forms\Components\Select;
use Pterodactyl\Filament\Resources\ModResource\Pages;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Pterodactyl\Models\Egg;
use Pterodactyl\Models\Mod;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;

class ModResource extends Resource
{
protected static ?string $model = Mod::class;

protected static ?string $navigationIcon = 'heroicon-o-document-arrow-down';

protected static ?string $navigationGroup = 'Service Management';

protected static ?int $navigationSort = 5;

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->required()
->maxLength(255),

Textarea::make('description')
->nullable(),

Select::make('eggs')
->multiple()
->options(Egg::query()->pluck('name', 'id'))
->searchable()
->preload()
->afterStateHydrated(function ($state, callable $set) {
if (is_array($state)) {
$set('eggs', array_map('intval', $state));
}
})
->dehydrateStateUsing(
fn ($state) => $state ? array_map('intval', $state) : []
),

Textarea::make('install_script')
->required()
->columnSpanFull(),

Textarea::make('uninstall_script')
->nullable()
->columnSpanFull(),

TextInput::make('docker_image')
->required(),

TextInput::make('entrypoint')
->required(),
]);
}

// table code excluded for conciseness

public static function getPages(): array
{
return [
'index' => Pages\ListMods::route('/'),
'create' => Pages\CreateMod::route('/create'),
'edit' => Pages\EditMod::route('/{record}/edit'),
];
}
}
<?php

namespace Pterodactyl\Filament\Resources;

use Filament\Forms\Components\Select;
use Pterodactyl\Filament\Resources\ModResource\Pages;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Pterodactyl\Models\Egg;
use Pterodactyl\Models\Mod;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;

class ModResource extends Resource
{
protected static ?string $model = Mod::class;

protected static ?string $navigationIcon = 'heroicon-o-document-arrow-down';

protected static ?string $navigationGroup = 'Service Management';

protected static ?int $navigationSort = 5;

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->required()
->maxLength(255),

Textarea::make('description')
->nullable(),

Select::make('eggs')
->multiple()
->options(Egg::query()->pluck('name', 'id'))
->searchable()
->preload()
->afterStateHydrated(function ($state, callable $set) {
if (is_array($state)) {
$set('eggs', array_map('intval', $state));
}
})
->dehydrateStateUsing(
fn ($state) => $state ? array_map('intval', $state) : []
),

Textarea::make('install_script')
->required()
->columnSpanFull(),

Textarea::make('uninstall_script')
->nullable()
->columnSpanFull(),

TextInput::make('docker_image')
->required(),

TextInput::make('entrypoint')
->required(),
]);
}

// table code excluded for conciseness

public static function getPages(): array
{
return [
'index' => Pages\ListMods::route('/'),
'create' => Pages\CreateMod::route('/create'),
'edit' => Pages\EditMod::route('/{record}/edit'),
];
}
}
4 replies
NNuxt
Created by Joshua on 7/31/2024 in #❓・help
Dynamic Sitemap Generation not working in production
No description
61 replies
FFilament
Created by Joshua on 3/28/2024 in #❓┊help
Form Saving with BelongsToMany Giving Headache
No description
3 replies