realstoyt's avatar

realstoyt started a new conversation+100 XP

3mos ago

I’m working with Filament (v3) and a RelationManager that has a fairly complex dynamic form.

Context

Resource: Order

RelationManager: OrderItemsRelationManager

The form dynamically builds slot sections based on the selected product.

Each slot has:

A Select field (orders.attachable_products)

A dynamic Rules section that depends on the selected attachable product

Everything is built using Schema components (not classic Forms API).

The Problem

From the UI perspective:

The orders.attachable_products select works

Options load correctly

Selection visually sticks

Dependent Rules sections render correctly

However, on form submit:

Validation fails with:

The orders.attachable_products field is required.

Additionally, earlier in debugging I was getting Livewire console errors like:

Livewire Entangle Error: Livewire property ['mountedActions.0.data.slot_glass_products'] cannot be found on component: ['app.filament.resources.orders.relation-managers.order-items-relation-manager']

Those entangle errors are now gone, but the required validation issue remains.

Key Observations

The Select field is clearly selected in the UI

But Laravel validation behaves as if the field is null

This only happens inside RelationManager table actions (Create/Edit modal)

The same pattern works fine for the main product select, but not for slot selects

Relevant Code (simplified) Slot select inside a dynamically generated Section Select::make("slot_{$slotKey}_products") ->label(__('orders.attachable_products')) ->options($attachableProducts) ->required($slotDefinition->is_required) ->reactive() ->afterStateUpdated(function ($state, Get $get, callable $set) use ($slotKey) { $currentAttachments = $get('selected_attachments') ?? [];

    $currentAttachments = array_filter(
        $currentAttachments,
        fn ($a) => ($a['slot_key'] ?? null) !== $slotKey
    );

    if ($state) {
        $currentAttachments[] = [
            'slot_key' => $slotKey,
            'product_ids' => [$state],
        ];
    }

    $set('selected_attachments', array_values($currentAttachments));
})
->afterStateHydrated(function (Select $component, $state, Get $get) use ($slotKey) {
    $attachments = $get('selected_attachments') ?? [];

    foreach ($attachments as $attachment) {
        if (($attachment['slot_key'] ?? null) === $slotKey) {
            $component->state($attachment['product_ids'][0] ?? null);
            break;
        }
    }
});

Slot rules depend on the same field Section::make('Rules') ->schema(function (Get $get) use ($slotKey) { $productId = $get("slot_{$slotKey}_products");

    if (! $productId) {
        return [];
    }

    return $this->productRulesInputs(
        (int) $productId,
        "slot_{$slotKey}_rules"
    );
})
->visible(fn (Get $get) => (bool) $get("slot_{$slotKey}_products"));

What I’m Trying to Understand

Why does a Select inside a RelationManager table action modal:

show selected state in UI

but still fail required validation?

Is there a known limitation or required pattern for:

dynamic Schema-based fields

inside RelationManager CreateAction / EditAction?

Is there something special about state dehydration or validation scope in RelationManagers vs normal Resource forms?

Additional Notes

I’m not manually touching mountedActions.* anywhere in PHP

The issue persists even when ->dehydrated(false) is removed

Main product selects and parameter selects work fine

Only dynamically generated slot-based selects fail validation

Any insight, patterns, or pointers to the correct Filament approach for this kind of dynamic RelationManager form would be hugely appreciated 🙏

realstoyt's avatar

realstoyt liked a comment+100 XP

3mos ago

I'm wondering how far Laravel's reach extends to. I hail from London myself.