fix: Do not fetch option labels for blank state (#17930)

This commit is contained in:
Dan Harrin
2025-09-24 22:44:40 +01:00
committed by GitHub
parent d39fdf6b3e
commit 2cfb9cdbbd
3 changed files with 23 additions and 6 deletions
@@ -641,6 +641,12 @@ class ModalTableSelect extends Field
return $values;
}
$state = $this->getState();
if (blank($state)) {
return null;
}
if ($this->isMultiple()) {
return array_keys($this->getOptionLabels(withDefaults: false));
}
+11 -2
View File
@@ -1447,6 +1447,11 @@ class Select extends Field implements Contracts\CanDisableOptions, Contracts\Has
}
$state = $this->getState();
if (blank($state)) {
return null;
}
$optionLabels = $this->getOptionLabels(withDefaults: false);
if (count($state) > count($optionLabels)) {
@@ -1477,14 +1482,18 @@ class Select extends Field implements Contracts\CanDisableOptions, Contracts\Has
throw new LogicException("Filament failed to validate the [{$this->getStatePath()}] field\'s selected options because it did not have an [options()] or [getOptionLabelUsing()] configuration. Please use one of these methods to inform Filament which options are valid for this field.");
}
$state = $this->getState();
if (blank($state)) {
return null;
}
$optionLabel = $this->getOptionLabel(withDefault: false);
if (blank($optionLabel)) {
return [];
}
$state = $this->getState();
if ($state instanceof BackedEnum) {
$state = $state->value;
}
+6 -4
View File
@@ -67,8 +67,6 @@ class SelectColumn extends Column implements Editable, HasEmbeddedView
protected ?Closure $getOptionLabelUsing = null;
protected ?Closure $getOptionLabelsUsing = null;
protected ?Closure $getOptionsSearchResultsUsing = null;
protected bool | Closure $shouldSearchOptionLabels = true;
@@ -144,6 +142,12 @@ class SelectColumn extends Column implements Editable, HasEmbeddedView
*/
public function getRules(): array
{
$state = $this->getState();
if (blank($state)) {
return $this->getBaseRules();
}
$optionLabel = $this->getOptionLabel(withDefault: false);
if (blank($optionLabel)) {
@@ -153,8 +157,6 @@ class SelectColumn extends Column implements Editable, HasEmbeddedView
];
}
$state = $this->getState();
if ($state instanceof BackedEnum) {
$state = $state->value;
}