diff --git a/docs/add-fields.md b/docs/add-fields.md index 38dde15f..2b705a57 100644 --- a/docs/add-fields.md +++ b/docs/add-fields.md @@ -58,9 +58,9 @@ public static function getOptions(): array And to apply these options to the field in the frontend: ```php -public function appendFilamentComponentsOptions($component, $zeusField) +public function appendFilamentComponentsOptions($component, $zeusField, $hasVisibility = false) { - parent::appendFilamentComponentsOptions($component, $zeusField); + parent::appendFilamentComponentsOptions($component, $zeusField, $hasVisibility); if (isset($zeusField->options['is_required']) && $zeusField->options['is_required']) { $component = $component->required(); diff --git a/src/Facades/Bolt.php b/src/Facades/Bolt.php index a7b35b11..3afe55d4 100644 --- a/src/Facades/Bolt.php +++ b/src/Facades/Bolt.php @@ -107,13 +107,15 @@ public static function prepareFieldsAndSectionToRender(Form $zeusForm): array $fields[] = static::renderHook('zeus-form-section.before'); + $hasVisibility = $section->fields()->pluck('options')->where('visibility.active', '!=', false)->isNotEmpty(); + foreach ($section->fields()->orderBy('ordering')->get() as $zeusField) { $fields[] = static::renderHook('zeus-form-field.before'); $fieldClass = new $zeusField->type; $component = $fieldClass->renderClass::make('zeusData.' . $zeusField->id); - $fields[] = $fieldClass->appendFilamentComponentsOptions($component, $zeusField); + $fields[] = $fieldClass->appendFilamentComponentsOptions($component, $zeusField, $hasVisibility); $fields[] = static::renderHook('zeus-form-field.after'); } diff --git a/src/Fields/Classes/CheckboxList.php b/src/Fields/Classes/CheckboxList.php index 091bb835..f42bfce3 100644 --- a/src/Fields/Classes/CheckboxList.php +++ b/src/Fields/Classes/CheckboxList.php @@ -30,9 +30,9 @@ public function getResponse($field, $resp): string return $this->getCollectionsValuesForResponse($field, $resp); } - public function appendFilamentComponentsOptions($component, $zeusField) + public function appendFilamentComponentsOptions($component, $zeusField, $hasVisibility = false) { - parent::appendFilamentComponentsOptions($component, $zeusField); + parent::appendFilamentComponentsOptions($component, $zeusField, $hasVisibility); $options = FieldsContract::getFieldCollectionItemsList($zeusField); diff --git a/src/Fields/Classes/FileUpload.php b/src/Fields/Classes/FileUpload.php index 40171f39..3dcc84ad 100644 --- a/src/Fields/Classes/FileUpload.php +++ b/src/Fields/Classes/FileUpload.php @@ -33,9 +33,9 @@ public function getResponse($field, $resp): string ->render(); } - public function appendFilamentComponentsOptions($component, $zeusField) + public function appendFilamentComponentsOptions($component, $zeusField, $hasVisibility = false) { - parent::appendFilamentComponentsOptions($component, $zeusField); + parent::appendFilamentComponentsOptions($component, $zeusField, $hasVisibility); $component->disk(config('zeus-bolt.uploads.disk')) ->directory(config('zeus-bolt.uploads.directory')); diff --git a/src/Fields/Classes/Radio.php b/src/Fields/Classes/Radio.php index 33f58812..18dd4a20 100644 --- a/src/Fields/Classes/Radio.php +++ b/src/Fields/Classes/Radio.php @@ -32,9 +32,9 @@ public function getResponse($field, $resp): string return $this->getCollectionsValuesForResponse($field, $resp); } - public function appendFilamentComponentsOptions($component, $zeusField) + public function appendFilamentComponentsOptions($component, $zeusField, $hasVisibility = false) { - parent::appendFilamentComponentsOptions($component, $zeusField); + parent::appendFilamentComponentsOptions($component, $zeusField, $hasVisibility); $options = FieldsContract::getFieldCollectionItemsList($zeusField); diff --git a/src/Fields/Classes/Select.php b/src/Fields/Classes/Select.php index a47a1252..dd0130e0 100644 --- a/src/Fields/Classes/Select.php +++ b/src/Fields/Classes/Select.php @@ -32,9 +32,9 @@ public function getResponse($field, $resp): string return $this->getCollectionsValuesForResponse($field, $resp); } - public function appendFilamentComponentsOptions($component, $zeusField) + public function appendFilamentComponentsOptions($component, $zeusField, $hasVisibility = false) { - parent::appendFilamentComponentsOptions($component, $zeusField); + parent::appendFilamentComponentsOptions($component, $zeusField, $hasVisibility); $options = FieldsContract::getFieldCollectionItemsList($zeusField); diff --git a/src/Fields/Classes/TextInput.php b/src/Fields/Classes/TextInput.php index e8d39544..502a094d 100644 --- a/src/Fields/Classes/TextInput.php +++ b/src/Fields/Classes/TextInput.php @@ -63,9 +63,9 @@ public static function getOptions(): array ]; } - public function appendFilamentComponentsOptions($component, $zeusField) + public function appendFilamentComponentsOptions($component, $zeusField, $hasVisibility = false) { - parent::appendFilamentComponentsOptions($component, $zeusField); + parent::appendFilamentComponentsOptions($component, $zeusField, $hasVisibility); if (! empty($zeusField['options']['dateType'])) { call_user_func([$component, $zeusField['options']['dateType']]); diff --git a/src/Fields/FieldsContract.php b/src/Fields/FieldsContract.php index 03414590..5ae51ec3 100644 --- a/src/Fields/FieldsContract.php +++ b/src/Fields/FieldsContract.php @@ -55,7 +55,7 @@ public function getResponse($field, $resp): string return $resp->response; } - public function appendFilamentComponentsOptions($component, $zeusField) + public function appendFilamentComponentsOptions($component, $zeusField, $hasVisibility = false) { $component ->label($zeusField->name) @@ -111,7 +111,11 @@ public function appendFilamentComponentsOptions($component, $zeusField) return in_array($get('zeusData.' . $relatedFields), $collection); }); - return $component->debounce(); + if ($hasVisibility) { + return $component->debounce(); + } + + return $component; } public function getCollectionsValuesForResponse($field, $resp): string