FilamentF
Filament17mo ago
daar

Conditional rules not working

Hi, I want to enable custom rules conditionally, but this is not being called. What am I missing here? I have attached the code used below.

                                Forms\Components\Select::make('identification_type')
  ->label(__('Identification type'))
  ->options(IdentificationType::class)
  ->live()
  ->required(),                              Forms\Components\TextInput::make('citizen_service_number')
  ->label(__('Identification number'))
  ->rules([
    static fn (Get $get): Closure => static function (string $attribute, $value, Closure $fail) use ($get): void {
      if ($get('identification_type') === IdentificationType::CEDULA->value) {
        $cedula = new Cedula($value);
          if ( ! $cedula->isValid()) {
            $fail(__('The citizen service number is invalid'));
          }
        }
      },
    ])
    ->maxLength(255),
Was this page helpful?