Custom form field

I need to update the product variants for a single product. To accomplish this, I've created a SlideOver Modal with custom field(ProductVariant::make('productId')) for the product variants. How can I get and update all the product variant data?

<?php
  Tables\Actions\Action::make("product-variant-modal")->label('Variant')
                ->modalHeading("product")
                    ->slideOver()
                    ->form([
                        ProductVariant::make('productId'),
                    ])
                ->modalDescription("Product description")
                    ->action(function (array $data): void {
                        dd($data);
                    }),

<?php
<x-dynamic-component
    :component="$getFieldWrapperView()"
    :field="$field"
>
    <?php
    $customDecorations = \App\Models\CustomDecoration::all()->pluck('decoration', 'decoration');
    ?>
    <div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
        @forelse($getRecord()->variants as  $productVariant)
            <div class="rounded-lg">
                <div class="min_height flex">
                    <input type="checkbox" class="mt-6 fi-checkbox-input">
                    <label class="text-xs mt-6 ms-1" >{{ $productVariant->description }}</label>
                </div>
                <select  class=" text-xs bg-gray-50 mt-1">
                    <option class="text-xs" value="">Please Select</option>
                    @foreach($customDecorations as $customDecoration)
                        <option class="text-xs"  value="{{ $customDecoration }}">{{ $customDecoration }}</option>
                    @endforeach
                </select>
            </div>
        @empty
            <span class="col-span-full text-xs">No product variant found.</span>
        @endforelse
    </div>
</x-dynamic-component>
image.png
image.png
image.png
Solution
Thank you very much, Leandro Ferreira, Toeknee, and Awcodes. I have finally resolved it.
I have just make a custom rule for it .
<?php
->form([
        Repeater::make('variants')
            ->relationship('variants')
            ->schema([
                Checkbox::make('is_approved'),
                Select::make('decoration_id')
                ...
            ])
    ])->rules([new AtLeastOneVariantChecked])


<?php 
public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        $atLeastOneVariantChecked = collect($value)->where('is_approved', true)->isNotEmpty();
        if ($atLeastOneVariantChecked === false) {
            $fail('');
            Notification::make()
                ->danger()
                ->title('At least one variant must be checked.')
                ->send();
        }
    }
Was this page helpful?