Skip to content

Commit 13e552f

Browse files
committed
Merge branch 'feat/conditional-fields' of github.com:backstagephp/fields into feat/conditional-fields
2 parents 5b1f57e + ea6e55c commit 13e552f

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/Fields/FormSchemas/VisibilityRulesSchema.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static function make(): array
4444
$excludeUlid = $record->ulid;
4545
}
4646
}
47+
4748
return FieldOptionsHelper::getFieldOptions($livewire, $excludeUlid);
4849
})
4950
->required(),
@@ -69,7 +70,7 @@ public static function make(): array
6970
->required(),
7071
Forms\Components\TextInput::make('value')
7172
->label(__('Value'))
72-
->visible(fn (Forms\Get $get): bool => !in_array($get('operator'), ['is_empty', 'is_not_empty'])),
73+
->visible(fn (Forms\Get $get): bool => ! in_array($get('operator'), ['is_empty', 'is_not_empty'])),
7374
])
7475
->collapsible()
7576
->itemLabel(function (array $state): ?string {
@@ -95,4 +96,4 @@ public static function make(): array
9596
]),
9697
];
9798
}
98-
}
99+
}

src/Fields/Logic/VisibilityLogicApplier.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ protected static function evaluateRuleConditions(Forms\Get $get, array $conditio
6868
return true;
6969
}
7070

71-
return $logic === 'AND'
72-
? !in_array(false, $results, true) // All must be true
71+
return $logic === 'AND'
72+
? ! in_array(false, $results, true) // All must be true
7373
: in_array(true, $results, true); // At least one must be true
7474
}
7575

@@ -113,21 +113,23 @@ protected static function evaluateCondition($fieldValue, string $operator, $expe
113113
return is_numeric($fieldValue) && is_numeric($expectedValue) && $fieldValue <= $expectedValue;
114114

115115
case 'in':
116-
if (!is_string($expectedValue)) {
116+
if (! is_string($expectedValue)) {
117117
return false;
118118
}
119119
$allowedValues = array_map('trim', explode(',', $expectedValue));
120+
120121
return in_array($fieldValue, $allowedValues);
121122

122123
case 'not_in':
123-
if (!is_string($expectedValue)) {
124+
if (! is_string($expectedValue)) {
124125
return true;
125126
}
126127
$excludedValues = array_map('trim', explode(',', $expectedValue));
127-
return !in_array($fieldValue, $excludedValues);
128+
129+
return ! in_array($fieldValue, $excludedValues);
128130

129131
default:
130132
return false;
131133
}
132134
}
133-
}
135+
}

0 commit comments

Comments
 (0)