© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•17mo ago•
4 replies
Sasa Orasanin

default value on dynamically added form fields

Forms\Components\Group::make(
  function (Get $get) {
      $collection = $get('component.collection') ?? [];

      return collect($collection)
          ->filter(function ($componentClass) {
              // Ensure the component class is valid
              return class_exists($componentClass);
          })
          ->map(function ($componentClass, $key) {
              // Dynamically resolve the component class and return its schema
              return Forms\Components\Section::make($componentClass::$title)
                  ->collapsible()
                  ->schema($componentClass::getSchema($key)); // Show only if it's the current component
          })
          ->toArray();  // Ensure it's an array of components
          }
    )->live()
Forms\Components\Group::make(
  function (Get $get) {
      $collection = $get('component.collection') ?? [];

      return collect($collection)
          ->filter(function ($componentClass) {
              // Ensure the component class is valid
              return class_exists($componentClass);
          })
          ->map(function ($componentClass, $key) {
              // Dynamically resolve the component class and return its schema
              return Forms\Components\Section::make($componentClass::$title)
                  ->collapsible()
                  ->schema($componentClass::getSchema($key)); // Show only if it's the current component
          })
          ->toArray();  // Ensure it's an array of components
          }
    )->live()

And one of component classes have:

public static function getSchema (string $key): array
{
    return [
        Forms\Components\TextInput::make($key . '.title')
            ->default('Some default text')
            ->required()
    ];
}
public static function getSchema (string $key): array
{
    return [
        Forms\Components\TextInput::make($key . '.title')
            ->default('Some default text')
            ->required()
    ];
}

Some default text is not appearing.. Anyone know why? Thanks
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Dynamically disable form fields on variable change
FilamentFFilament / ❓┊help
2y ago
Default value and reactive fields
FilamentFFilament / ❓┊help
3y ago
default value on form select not populating
FilamentFFilament / ❓┊help
3y ago