Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AddressFields.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Filament\Forms\Components;
  3. use Filament\Forms\Components\Field;
  4. use Filament\Forms\Components\Grid;
  5. use Filament\Forms\Components\TextInput;
  6. class AddressFields extends Grid
  7. {
  8. protected bool $isSoftRequired = false;
  9. protected function setUp(): void
  10. {
  11. parent::setUp();
  12. $this->schema([
  13. TextInput::make('address_line_1')
  14. ->label('Address Line 1')
  15. ->required()
  16. ->maxLength(255),
  17. TextInput::make('address_line_2')
  18. ->label('Address Line 2')
  19. ->maxLength(255),
  20. CountrySelect::make('country')
  21. ->clearStateField()
  22. ->required(),
  23. StateSelect::make('state_id'),
  24. TextInput::make('city')
  25. ->label('City')
  26. ->required()
  27. ->maxLength(255),
  28. TextInput::make('postal_code')
  29. ->label('Postal Code / Zip Code')
  30. ->maxLength(255),
  31. ]);
  32. }
  33. public function softRequired(bool $condition = true): static
  34. {
  35. $this->setSoftRequired($condition);
  36. return $this;
  37. }
  38. protected function setSoftRequired(bool $condition): void
  39. {
  40. $this->isSoftRequired = $condition;
  41. $childComponents = $this->getChildComponents();
  42. foreach ($childComponents as $component) {
  43. if ($component instanceof Field && $component->isRequired()) {
  44. $component->markAsRequired(! $condition);
  45. }
  46. }
  47. }
  48. }