Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Editor 2.4.0 tags field support #232

Merged
merged 8 commits into from
Jan 9, 2025
Merged

feat: add Editor 2.4.0 tags field support #232

merged 8 commits into from
Jan 9, 2025

Conversation

yajra
Copy link
Owner

@yajra yajra commented Jan 9, 2025

Add support for Editor 2.4.0 tags field

Client-side

use Yajra\DataTables\Html\Editor\Fields\Tags;

Tags::make('permissions[].id')
    ->name('permissions')
    ->addButton('Add Permission')
    ->title('Permission Tags')
    ->noResults('No permissions found.')
    ->placeholder('Type to search permissions')
    ->inputPlaceholder('Search permissions')
    ->limit(2)
    ->label('Permissions')
    ->tableOptions('permissions', 'name'),

Server-side via AJAX with Editor action

Field

use Yajra\DataTables\Html\Editor\Fields\Tags;

Tags::make('permissions[].id')
    ->name('permissions')
    ->addButton('Add Permission')
    ->title('Permission Tags')
    ->noResults('No permissions found.')
    ->placeholder('Type to search permissions')
    ->inputPlaceholder('Search permissions')
    ->limit(2)
    ->label('Permissions')
    ->ajax(),

Editor

    protected array $customActions = ['search'];

    public function search(Request $request): JsonResponse
    {
        $search = $request->get('search');

        $permissions = Permission::query()
            ->whereLike('name', "%{$search}%")
            ->paginate()
            ->map(function (User $permission) {
                return [
                    'value' => $permission->id,
                    'label' => $permission->name,
                ];
            });

        return $this->toJson($permissions->toArray());
    }

Copy link

sonarqubecloud bot commented Jan 9, 2025

@yajra yajra merged commit dd40155 into master Jan 9, 2025
11 checks passed
@yajra yajra deleted the tags branch January 9, 2025 14:59
@yajra yajra changed the title feat: add tags field support feat: add Editor 2.4.0 tags field support Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant