F
Filament14mo ago
kool

HelperText is not shown in a Page contains a simple form.

I am currently studying Filament, and I am exploring the Form Builder section. So I decided to create a simple page with a form to try out the various fields, etc.. I added helperText to certain column and also a column that appear if a specific value is set but either the column is not shown or the helper text PHP: 8.2.11 Laravel: 10.10 Filament: 3.0-stable
No description
No description
5 Replies
DrByte
DrByte14mo ago
Your screenshots of code are very hard to read. That's why the #✅┊rules say to post the text of your code inside code tags (triple-backticks, like GitHub) or in a gist. It looks like your helperText() is trying to display a DatePicker() element inside it? Why?
kool
koolOP14mo ago
## imports
namespace App\Filament\Pages;

use Filament\Forms\Components\Concerns\HasHelperText;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Pages\Page;
## imports
namespace App\Filament\Pages;

use Filament\Forms\Components\Concerns\HasHelperText;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Pages\Page;
<?php

class FormExample extends Page implements HasForms
{
use InteractsWithForms;
use HasHelperText;

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

protected static string $view = 'filament.pages.form';

public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}

public function form(Form $form): Form
{
return $form
->schema([
Section::make('Publishing')
->description('Settings for publishing this post.')
->schema([
Select::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->live()
->helperText(fn(Get $get) => match ($get('status')) {
'draft', 'reviewing'
=> str('This post **will not be visible** to the public until it is published.')
->inlineMarkdown()->toHtmlString(),
'published'
=> str('This post **is visible** to the public.')->inlineMarkdown()->toHtmlString(),
default => '',
})->live(),
DateTimePicker::make('published_at')
->hidden(fn(Get $get) => $get('status') !== 'published'),
]),
]);
}
}
<?php

class FormExample extends Page implements HasForms
{
use InteractsWithForms;
use HasHelperText;

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

protected static string $view = 'filament.pages.form';

public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}

public function form(Form $form): Form
{
return $form
->schema([
Section::make('Publishing')
->description('Settings for publishing this post.')
->schema([
Select::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->live()
->helperText(fn(Get $get) => match ($get('status')) {
'draft', 'reviewing'
=> str('This post **will not be visible** to the public until it is published.')
->inlineMarkdown()->toHtmlString(),
'published'
=> str('This post **is visible** to the public.')->inlineMarkdown()->toHtmlString(),
default => '',
})->live(),
DateTimePicker::make('published_at')
->hidden(fn(Get $get) => $get('status') !== 'published'),
]),
]);
}
}
DatePicker is another column, it is not inside helperText
DrByte
DrByte14mo ago
At the risk of sounding obvious, does the helperText work properly if you change it just to a simple string, like "test"? I wonder if it's hitting your default=>'' in all cases, which makes it seem like it's not displaying... Also, you have two ->live() on the same Select, before and after the helperText declaration. Harmless, but duplicate.
kool
koolOP14mo ago
Yeah you are right, didn't notice it. I will check this out I tried to change it to a simple text and it works but this is strange because I have done the same thing inside a resource page with the same lines of code its form method. Also the same applies in DatePicker column, it does appear If I put it inside a a resource page but a page without resource not working. I don't know it it is a bug or I am missing something.
DrByte
DrByte14mo ago
I would have expected the InteractsWithForms trait to be enough, but maybe it's worth exploring (source-diving) what other traits are on a Resource that aren't on your page. (I'd look myself now, but don't have my full IDE with me 🙂 )
Want results from more Discord servers?
Add your server