Skip to content

Commit d5f6804

Browse files
committed
Merge branch 'feat/form-layout-components' of github.com:backstagephp/fields into feat/form-layout-components
2 parents 6ee4055 + d130fdb commit d5f6804

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

src/Concerns/HasSelectableValues.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected static function buildRelationshipOptions(mixed $field): array
117117
if (isset($relation['relationValue_filters'])) {
118118
foreach ($relation['relationValue_filters'] as $filter) {
119119
if (isset($filter['column'], $filter['operator'], $filter['value']) &&
120-
! empty($filter['column']) && ! empty($filter['operator']) && $filter['value'] !== '') {
120+
! empty($filter['column']) && ! empty($filter['operator']) && $filter['value'] !== null) {
121121
if (preg_match('/{session\.([^\}]+)}/', $filter['value'], $matches)) {
122122
$sessionValue = session($matches[1]);
123123
$filter['value'] = str_replace($matches[0], $sessionValue, $filter['value']);

src/Fields/Repeater.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Filament\Schemas\Components\Utilities\Get;
2424
use Filament\Schemas\Components\Utilities\Set;
2525
use Filament\Support\Enums\Alignment;
26+
use Forms\Components\Placeholder;
2627
use Illuminate\Support\Collection;
2728
use Illuminate\Support\Str;
2829
use Saade\FilamentAdjacencyList\Forms\Components\AdjacencyList;

src/Fields/Select.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public static function make(string $name, ?Field $field = null): Input
7070
if (isset($field->config['dependsOnField']) && $field->config['dependsOnField']) {
7171
$input = self::addFieldDependency($input, $field);
7272
}
73-
73+
7474
// Add dynamic options first (from relationships, etc.)
7575
$input = self::addOptionsToInput($input, $field);
76-
76+
7777
// Set static options as fallback if no dynamic options were added
78-
if (empty($field->config['optionType']) || !is_array($field->config['optionType']) || !in_array('relationship', $field->config['optionType'])) {
78+
if (empty($field->config['optionType']) || ! is_array($field->config['optionType']) || ! in_array('relationship', $field->config['optionType'])) {
7979
$input = $input->options($field->config['options'] ?? self::getDefaultConfig()['options']);
8080
}
8181

@@ -110,13 +110,12 @@ protected static function addFieldDependency(Input $input, Field $field): Input
110110
// The field name in the form is {valueColumn}.{field_ulid}
111111
$dependentFieldName = "values.{$dependsOnField}";
112112
$dependentValue = $get($dependentFieldName);
113-
113+
114114
// Show this field only when the dependent field has a value
115-
return !empty($dependentValue);
115+
return ! empty($dependentValue);
116116
});
117117
}
118118

119-
120119
public static function mutateFormDataCallback(Model $record, Field $field, array $data): array
121120
{
122121
if (! property_exists($record, 'valueColumn')) {
@@ -258,30 +257,30 @@ public function getForm(): array
258257
->options(function ($record, $component) {
259258
// Try to get the form slug from various sources
260259
$formSlug = null;
261-
260+
262261
// Method 1: From the record's model_key (most reliable)
263262
if ($record && isset($record->model_key)) {
264263
$formSlug = $record->model_key;
265264
}
266-
265+
267266
// Method 2: From route parameters as fallback
268-
if (!$formSlug) {
267+
if (! $formSlug) {
269268
$routeParams = request()->route()?->parameters() ?? [];
270269
$formSlug = $routeParams['record'] ?? $routeParams['form'] ?? $routeParams['id'] ?? null;
271270
}
272-
271+
273272
// Method 3: Try to get from the component's owner record if available
274-
if (!$formSlug && method_exists($component, 'getOwnerRecord')) {
273+
if (! $formSlug && method_exists($component, 'getOwnerRecord')) {
275274
$ownerRecord = $component->getOwnerRecord();
276275
if ($ownerRecord) {
277276
$formSlug = $ownerRecord->getKey();
278277
}
279278
}
280-
281-
if (!$formSlug) {
279+
280+
if (! $formSlug) {
282281
return ['debug' => 'No form slug found. Record: ' . ($record ? json_encode($record->toArray()) : 'null')];
283282
}
284-
283+
285284
// Get all select fields in the same form
286285
$fields = \Backstage\Fields\Models\Field::where('model_type', 'App\Models\Form')
287286
->where('model_key', $formSlug)
@@ -292,17 +291,17 @@ public function getForm(): array
292291
->orderBy('name')
293292
->pluck('name', 'ulid')
294293
->toArray();
295-
294+
296295
if (empty($fields)) {
297296
return ['debug' => 'No select fields found for form: ' . $formSlug . '. Total fields: ' . \Backstage\Fields\Models\Field::where('model_type', 'App\Models\Form')->where('model_key', $formSlug)->count()];
298297
}
299-
298+
300299
return $fields;
301300
})
302301
->searchable()
303302
->live(),
304303
]),
305-
]),
304+
]),
306305
Tab::make('Rules')
307306
->label(__('Rules'))
308307
->schema([

src/Models/Field.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Backstage\Fields\Models;
44

55
use Backstage\Fields\Shared\HasPackageFactory;
6-
use Carbon\Carbon;
7-
use Illuminate\Database\Eloquent\Collection;
86
use Illuminate\Database\Eloquent\Concerns\HasUlids;
97
use Illuminate\Database\Eloquent\Model;
108
use Illuminate\Database\Eloquent\Relations\BelongsTo;

tests/SelectCascadingTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
$reflection = new ReflectionClass($input);
4949
$liveProperty = $reflection->getProperty('isLive');
5050
$liveProperty->setAccessible(true);
51-
51+
5252
expect($liveProperty->getValue($input))->toBeTrue();
5353
});
5454

@@ -67,7 +67,7 @@
6767
$reflection = new ReflectionClass($input);
6868
$liveProperty = $reflection->getProperty('isLive');
6969
$liveProperty->setAccessible(true);
70-
70+
7171
$isLive = $liveProperty->getValue($input);
7272
expect($isLive)->toBeNull(); // Regular select fields don't have isLive set
7373
});
@@ -78,8 +78,10 @@
7878
'config' => ['multiple' => false],
7979
]);
8080

81-
$record = new class extends Model {
81+
$record = new class extends Model
82+
{
8283
public $valueColumn = 'values';
84+
8385
public $values = ['test_field' => 'single_value'];
8486
};
8587

@@ -95,8 +97,10 @@
9597
'config' => ['multiple' => true],
9698
]);
9799

98-
$record = new class extends Model {
100+
$record = new class extends Model
101+
{
99102
public $valueColumn = 'values';
103+
100104
public $values = ['test_field' => '["value1", "value2"]'];
101105
};
102106

@@ -112,8 +116,10 @@
112116
'config' => ['multiple' => false],
113117
]);
114118

115-
$record = new class extends Model {
119+
$record = new class extends Model
120+
{
116121
public $valueColumn = 'values';
122+
117123
public $values = ['test_field' => null];
118124
};
119125

@@ -130,8 +136,10 @@
130136
'config' => ['multiple' => true],
131137
]);
132138

133-
$record = new class extends Model {
139+
$record = new class extends Model
140+
{
134141
public $valueColumn = 'values';
142+
135143
public $values = ['test_field' => null];
136144
};
137145

0 commit comments

Comments
 (0)