Skip to content

Commit

Permalink
Add disabled form fields logic to edit/create page
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Apr 17, 2024
1 parent eff8d29 commit c139794
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/Stubs/Resource/Page/Create/Form/Fields/Disabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ class Disabled extends Base

public function getDescription(): string
{
return 'has a disabled X field on create form';
return 'has a disabled field on create form';
}

public function getShouldGenerate(): bool
{
return collect($this->getResourceCreateFields($this->resource))
->filter(fn ($field) => $field->isDisabled())->count();
}

public function getVariables(): array
{
return [
'CREATE_PAGE_DISABLED_FIELDS' => $this->convertDoubleQuotedArrayString(collect($this->getResourceCreateFields($this->resource))->filter(fn ($field) => $field->isDisabled())->keys()),
];
}
}
9 changes: 8 additions & 1 deletion src/Stubs/Resource/Page/Edit/Form/Fields/Disabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ class Disabled extends Base

public function getDescription(): string
{
return 'has a disabled X field on edit form';
return 'has a disabled field on edit form';
}

public function getShouldGenerate(): bool
{
return collect($this->getResourceEditFields($this->resource))
->filter(fn ($field) => $field->isDisabled())->count();
}

public function getVariables(): array
{
return [
'EDIT_PAGE_DISABLED_FIELDS' => $this->convertDoubleQuotedArrayString(collect($this->getResourceEditFields($this->resource))->filter(fn ($field) => $field->isDisabled())->keys()),
];
}
}
7 changes: 4 additions & 3 deletions stubs/Resource/Page/Create/Form/Fields/Disabled.stub
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
it({{ DESCRIPTION }}, function () {
//
}){{ RESOLVED_GROUP_METHOD }}->todo();
it({{ DESCRIPTION }}, function (string $field) {
livewire({{ RESOURCE_CREATE_CLASS}})
->assertFormFieldIsDisabled($field);
})->with({{ CREATE_PAGE_DISABLED_FIELDS }}){{ RESOLVED_GROUP_METHOD }};
9 changes: 6 additions & 3 deletions stubs/Resource/Page/Edit/Form/Fields/Disabled.stub
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
it({{ DESCRIPTION }}, function () {
//
}){{ RESOLVED_GROUP_METHOD }}->todo();
it({{ DESCRIPTION }}, function (string $field) {
$record = {{ MODEL_SINGULAR_NAME }}::factory()->create();

livewire({{ RESOURCE_EDIT_CLASS}}, ['record' => $record->getRouteKey()])
->assertFormFieldIsDisabled($field);
})->with({{ EDIT_PAGE_DISABLED_FIELDS }}){{ RESOLVED_GROUP_METHOD }};

0 comments on commit c139794

Please sign in to comment.