stepanenko3 / nova-boolean-group-field

Nova BooleanGroup advanced field based on native Nova field
MIT License
6 stars 0 forks source link

Change the sort of items #3

Open wamesro opened 10 months ago

wamesro commented 10 months ago

Is it possible to change the sort of items? We would need 2019 to be at the beginning

In the preview you have it with your own sort https://github.com/stepanenko3/nova-boolean-group-field/raw/main/screenshots/field.png

I tried both krsort() and array_reverse()

Snímka obrazovky 2023-10-26 o 9 41 36

We use it in Action

Select::make(__('order_item.action.bulk.field.product'), 'product')
    ->help(__('order_item.action.bulk.field.product.help'))
    ->options(ProductController::getActiveProducts())
    ->searchable()
    ->required()
    ->rules('required'),

BooleanGroup::make(__('order_item.action.bulk.field.variant'), 'variant')
    ->help(__('order_item.action.bulk.field.variant.help'))
    ->required()
    ->rules('required')
    ->dependsOn('product', function (BooleanGroup $field, NovaRequest $request, FormData $formData): void {
        $options = [];

        $productId = $formData->product;
        if ($productId) {
            $options = ProductVariantController::getVariantsByProductId($productId);
        }

        $field->options(0 === count($options) ? [] $options);
    }),