Skip to content

[폼.필드] Radio ​

개요 ​

라디오 입력은 미리 정의된 옵션 목록에서 단일 값을 선택할 수 있는 라디오 버튼 그룹을 제공합니다:

php
use Filament\Forms\Components\Radio;

Radio::make('status')
    ->options([
        'draft' => 'Draft',
        'scheduled' => 'Scheduled',
        'published' => 'Published'
    ])
Radio

옵션 설명 설정하기 ​

descriptions() 메서드를 사용하여 각 옵션에 설명을 추가할 수 있습니다:

php
use Filament\Forms\Components\Radio;

Radio::make('status')
    ->options([
        'draft' => 'Draft',
        'scheduled' => 'Scheduled',
        'published' => 'Published'
    ])
    ->descriptions([
        'draft' => '보이지 않습니다.',
        'scheduled' => '곧 보이게 됩니다.',
        'published' => '보입니다.'
    ])
Radio with option descriptions

설명 배열에서 옵션 배열의 key와 동일한 key를 사용해야 올바른 설명이 올바른 옵션에 매칭됩니다.

불리언 옵션 ​

"예"와 "아니오" 옵션이 있는 간단한 불리언 라디오 버튼 그룹을 원한다면, boolean() 메서드를 사용할 수 있습니다:

php
Radio::make('feedback')
    ->label('이 게시글이 마음에 드시나요?')
    ->boolean()
Boolean radio

라벨과 옵션을 한 줄에 배치하기 ​

옵션을 라벨 아래가 아니라 inline()으로 라벨과 한 줄에 표시하고 싶을 수 있습니다:

php
Radio::make('feedback')
    ->label('이 게시글이 마음에 드시나요?')
    ->boolean()
    ->inline()
Inline radio

라벨 아래에서 옵션끼리 한 줄에 배치하기 ​

옵션을 라벨 아래에서 옵션끼리 inline()으로 한 줄에 표시하고 싶을 수 있습니다:

php
Radio::make('feedback')
    ->label('이 게시글이 마음에 드시나요?')
    ->boolean()
    ->inline()
    ->inlineLabel(false)
Inline radio under label

특정 옵션 비활성화하기 ​

disableOptionWhen() 메서드를 사용하여 특정 옵션을 비활성화할 수 있습니다. 이 메서드는 클로저를 인자로 받아, 특정 $value를 가진 옵션을 비활성화할지 여부를 확인할 수 있습니다:

php
use Filament\Forms\Components\Radio;

Radio::make('status')
    ->options([
        'draft' => 'Draft',
        'scheduled' => 'Scheduled',
        'published' => 'Published',
    ])
    ->disableOptionWhen(fn (string $value): bool => $value === 'published')
Radio with disabled option

비활성화되지 않은 옵션만 가져오고 싶다면(예: 유효성 검사 목적 등), getEnabledOptions()을 사용할 수 있습니다:

php
use Filament\Forms\Components\Radio;

Radio::make('status')
    ->options([
        'draft' => 'Draft',
        'scheduled' => 'Scheduled',
        'published' => 'Published',
    ])
    ->disableOptionWhen(fn (string $value): bool => $value === 'published')
    ->in(fn (Radio $component): array => array_keys($component->getEnabledOptions()))

나를 위한 문서 한글화