Dynamically change form fields in Filament Laravel

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Dynamically Change Form Fields in Filament Laravel - A Comprehensive Guide Filament is an excellent tool for building powerful web applications using the Laravel framework. One of its notable features is dynamic form generation, which enables developers to create forms with custom fields based on different conditions and user interactions. This blog post will provide a thorough answer to dynamically changing form fields in Filament Laravel based on a checkBoxList. Step 1: Understand the Problem Your goal is to generate new input fields when a specific option (in this case, the color of the product) is selected from a checkbox list. This requires implementing dynamic changes for those fields based on input from the user. Step 2: Define the CheckboxList Component Create a CheckboxList component that includes your desired options. In this example, we will use colors as our options. ```php $checkboxes = [ 'red' => 'Red', 'blue' => 'Blue', 'green' => 'Green', ]; @foreach ($checkboxes as $key => $value) @endforeach ``` Step 3: Create the Input Fields Each input field should have a unique name and be created dynamically based on the chosen option from the checkbox list. We will use an array of fields, where each element represents a different field: ```php $fields = []; foreach ($checkboxes as $key => $value) { $fields[$key] = [ 'type' => 'text', 'label' => "Enter the value for your $value", ]; } @foreach ($fields as $field) @endforeach ``` Step 4: Bind the Fields with Form State Since Filament uses form state for dynamic forms, you need to bind the input fields to the global form state. This ensures that the fields only appear when a specific checkbox is checked and hides away when unchecked. You can update your code as follows: ```php use Illuminate\Support\Facades\App; $fieldMap = App::make('filament\forms\Components\StateManager')->createFields(); foreach ($fields as $key => $value) { $fieldMap->registerField($key, $field); } ``` Step 5: Add Form Processing Logic Lastly, you need to handle the form submission by validating and updating the data in your database. Since we are adding new fields dynamically, we will use Filament's built-in validation mechanism. The best practice is to validate each field individually using a custom rule group or standard Laravel rules: ```php $request->validate([ 'colors' => ['required', 'array'], // CheckboxList requirement 'red_value' => 'nullable|string', // Input field for red color value 'blue_value' => 'nullable|string', // Input field for blue color value 'green_value' => 'nullable|string', // Input field for green color value ]); ``` Step 6: Conclusion Now you can dynamically change form fields in Filament Laravel based on a checkbox list. Remember to use good naming conventions and proper data validation methods to ensure your application is robust and efficient. To learn more about dynamic forms and other useful Filament features, feel free to visit our website at https://laravelcompany.com.