Skip to content

Commit

Permalink
support locking forms
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wesely committed Aug 5, 2024
1 parent 222e563 commit 9dee93c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@
$table->text('redirect_url')->nullable();
});
```

## Support locking a form to prevent data integrity issues
1.2 supports locking forms so that entries from a form can always be compared apples to apples over time with no risk of the form being changed and previous entries becoming incompatible with new entires. If you are upgrading from 1.0 or 1.1 to 1.2, create a migration with the following method to reflect this change
```
Schema::table('filament_forms', function (Blueprint $table) {
$table->boolean('locked')->default(false);
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ return new class extends Migration
$table->timestamps();
$table->string('name');
$table->text('description')->nullable();
$table->text('redirect_url')->nullable();
$table->boolean('permit_guest_entries')->default(false);
$table->boolean('locked')->default(false);
});

Schema::create('filament_form_fields', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

namespace Tapp\FilamentFormBuilder\Filament\Resources\FilamentFormResource\RelationManagers;

use Filament\Tables;
use Filament\Forms\Get;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Filament\Tables\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TagsInput;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Filament\Forms\Components\TagsInput;
use Filament\Forms\Components\TextInput;
use Filament\Resources\RelationManagers\RelationManager;
use Tapp\FilamentFormBuilder\Enums\FilamentFieldTypeEnum;

class FilamentFormFieldsRelationManager extends RelationManager
Expand Down Expand Up @@ -58,6 +59,8 @@ public function form(Form $form): Form

public function table(Table $table): Table
{
$form = $this->getOwnerRecord();

return $table
->recordTitleAttribute('label')
->heading(config('filament-form-builder.admin-panel-filament-form-field-name-plural'))
Expand All @@ -80,15 +83,49 @@ public function table(Table $table): Table
])
->headerActions([
Tables\Actions\CreateAction::make()
->visible(function () use ($form) {
!$form->locked;
})
->label('Create Field'),
Action::make('lock_fields')
->requiresConfirmation()
->modalHeading('Lock Form Fields. Doing this will lock the forms fields and new fields will no longer be able to be changed or edited')
->visible(function () use ($form) {
!$form->locked;
})
->action(function () use ($form) {
$form->update([
'locked' => true,
]);
}),
Action::make('unlock_fields')
->requiresConfirmation()
->modalHeading('Unlock Form Fields. Changing fields after entries has been made can cause inconsistencies for prexisting entries')
->visible(function () use ($form) {
!$form->locked;
})
->action(function () use ($form) {
$form->update([
'locked' => true,
]);
})
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\EditAction::make()
->visible(function () use ($form) {
!$form->locked;
}),
Tables\Actions\DeleteAction::make()
->visible(function () use ($form) {
!$form->locked;
}),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\DeleteBulkAction::make()
->visible(function () use ($form) {
!$form->locked;
}),
]),
]);
}
Expand Down

0 comments on commit 9dee93c

Please sign in to comment.