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

feature: Builder component: ability to disable add / delete button [Forms] #1031

Merged
merged 5 commits into from Dec 28, 2021

Conversation

imbue
Copy link
Contributor

@imbue imbue commented Dec 27, 2021

Offers the possibility to disable the adding and/or removing of items (blocks) in the block builder component. Along with the existing "disableItemMovement" there will be two new methods available:

->disableItemCreation($bool | Closure $condition = true)

->disableItemDeletion($bool | Closure $condition = true)

Example

public static function form(Form $form): Form
{
    return $form
        ->schema([
            Builder::make('blocks')
                ->disableItemCreation(true)
                ->disableItemDeletion(true)

                // existing method
                ->disableItemMovement(false)
                ->blocks([
                    Builder\Block::make('heading')
                        ->schema([
                            TextInput::make('content')->required(),
                            Select::make('level')
                                ->options([
                                    'h1' => 'Heading 1',
                                    'h2' => 'Heading 2',
                                ])
                                ->required(),
                        ]),
                    Builder\Block::make('paragraph')
                        ->schema([
                            MarkdownEditor::make('content')->required(),
                        ]),
                ])
        ]);
}

@patrickdokter
Copy link

Would be very nice to have!

@danharrin danharrin added the enhancement New feature or request label Dec 28, 2021
@danharrin danharrin merged commit 7586984 into filamentphp:2.x Dec 28, 2021
@danharrin
Copy link
Member

Hey! Thanks for this.

I went a bit overboard and also implemented this for the repeater, and refreshed the UI for both components:

@SebastiaanKloos
Copy link
Contributor

Hey! Thanks for this.

I went a bit overboard and also implemented this for the repeater, and refreshed the UI for both components:

Thanks @danharrin, this is much better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants