diff --git a/app/Filament/Forms/Resources/FormVersionResource.php b/app/Filament/Forms/Resources/FormVersionResource.php index e4d2ce8..4366423 100644 --- a/app/Filament/Forms/Resources/FormVersionResource.php +++ b/app/Filament/Forms/Resources/FormVersionResource.php @@ -118,20 +118,31 @@ public static function form(Form $form): Form ->cloneable() ->collapsible() ->collapsed(true) + ->live() ->itemLabel(function ($state) { if ($state['component_type'] === 'form_field') { $field = FormField::find($state['form_field_id']) ?: null; - $field ? $label = ($state['custom_label'] ?: ($field->label ?? '')) - . ' - ' . $field->dataType->short_description - . ' (' . ($field->name ?? '') . ')' - : $label = 'New Field'; - return $label; + if ($field) { + $label = ''; + if ($state['customize_label'] !== 'hide') { + $label .= ($state['custom_label'] ?? $field->label ?? 'null') . ' | '; + } else { + $label .= '(label hidden) | '; + } + $label .= ($field->dataType->name ?? '') + . ' | id: ' . ($state['custom_instance_id'] ?? $state['instance_id'] ?? ''); + return $label; + } + return 'New Field'; } elseif ($state['component_type'] === 'field_group') { $group = FieldGroup::find($state['field_group_id']); - $group ? $label = ($state['group_label'] ?: ($group->label ?? '')) - . ' (' . ($group->name ?? '') . ')' - : $label = 'New Group'; - return $label; + if ($group) { + $label = ($state['group_label'] ?? $group->label ?? '(no label)') + . ' | group ' + . ' | id: ' . ($state['custom_instance_id'] ?? $state['instance_id'] ?? ''); + return $label; + } + return 'New Group'; } return 'Component'; }) @@ -154,13 +165,14 @@ public static function form(Form $form): Form foreach ($options as $id => $option) { $field = FormField::find($id) ?: null; $options[$id] = $option - . ' - ' . $field->dataType->short_description - . ' (' . ($field->name ?? '') . ')'; + . ' | ' . $field->dataType->name + . ' | name: ' . ($field->name ?? ''); } return $options; }) ->searchable() - ->required(), + ->required() + ->reactive(), Fieldset::make('Field Value') ->visible(fn($get) => FormField::find($get('form_field_id'))?->isValueInputNeededForField() ?? false) ->columns(1) @@ -262,9 +274,15 @@ public static function form(Form $form): Form ->default('default') ->inline() ->inlineLabel(false) - ->live(), + ->live() + ->afterStateUpdated(function ($state, callable $set) { + if ($state !== 'customize') { + $set('custom_label', null); + } + }), TextInput::make('custom_label') ->label(false) + ->reactive() ->visible(fn($get) => $get('customize_label') == 'customize'), ]), Fieldset::make('Instance ID') @@ -330,7 +348,7 @@ public static function form(Form $form): Form // Compose option labels $options = FieldGroup::pluck('label', 'id'); foreach ($options as $id => $option) { - $options[$id] = $option . ' (' . (FieldGroup::find($id)->name ?? '') . ')'; + $options[$id] = ($option ?? '(no label)') . ' | group | name: ' . (FieldGroup::find($id)->name ?? ''); } return $options; }) @@ -407,13 +425,21 @@ public static function form(Form $form): Form ->cloneable() ->collapsible() ->collapsed() + ->live() ->itemLabel(function ($state) { $field = FormField::find($state['form_field_id']) ?: null; - $field ? $label = ($state['label'] ?: ($field->label ?? 'New Field')) - . ' - ' . $field->dataType->short_description - . ' (' . ($field->name ?? 'empty') . ')' - : $label = 'New Field'; - return $label; + if ($field) { + $label = ''; + if ($state['customize_label'] !== 'hide') { + $label .= ($state['custom_label'] ?? $field->label ?? '') . ' | '; + } else { + $label .= '(label hidden) | '; + } + $label .= ($field->dataType->name ?? '') + . ' | id: ' . ($state['custom_instance_id'] ?? $state['instance_id'] ?? ''); + return $label; + } + return 'New Field'; }) ->defaultItems(0) ->schema([ @@ -425,13 +451,14 @@ public static function form(Form $form): Form foreach ($options as $id => $option) { $field = FormField::find($id) ?: null; $options[$id] = $option - . ' - ' . $field->dataType->short_description - . ' (' . ($field->name ?? '') . ')'; + . ' | ' . $field->dataType->name + . ' | name: ' . ($field->name ?? ''); } return $options; }) ->searchable() - ->required(), + ->required() + ->reactive(), Fieldset::make('Field Value') ->visible(fn($get) => FormField::find($get('form_field_id'))?->isValueInputNeededForField() ?? false) ->columns(1) @@ -533,9 +560,15 @@ public static function form(Form $form): Form ->default('default') ->inline() ->inlineLabel(false) - ->live(), + ->live() + ->afterStateUpdated(function ($state, callable $set) { + if ($state !== 'customize') { + $set('custom_label', null); + } + }), TextInput::make('custom_label') ->label(false) + ->reactive() ->visible(fn($get) => $get('customize_label') == 'customize'), ]), Fieldset::make('Instance ID') diff --git a/app/Filament/Forms/Resources/FormVersionResource/Pages/EditFormVersion.php b/app/Filament/Forms/Resources/FormVersionResource/Pages/EditFormVersion.php index 9928caf..5711148 100644 --- a/app/Filament/Forms/Resources/FormVersionResource/Pages/EditFormVersion.php +++ b/app/Filament/Forms/Resources/FormVersionResource/Pages/EditFormVersion.php @@ -58,7 +58,7 @@ protected function afterSave(): void 'form_version_id' => $formVersion->id, 'form_field_id' => $component['form_field_id'], 'order' => $order, - 'custom_label' => $component['customize_label'] == 'customize' ? $component['custom_label'] : null, + 'custom_label' => $component['customize_label'] === 'customize' ? $component['custom_label'] : null, 'customize_label' => $component['customize_label'] ?? null, 'custom_data_binding_path' => $component['customize_data_binding_path'] ? $component['custom_data_binding_path'] : null, 'custom_data_binding' => $component['customize_data_binding'] ? $component['custom_data_binding'] : null, @@ -194,7 +194,7 @@ protected function mutateFormDataBeforeFill(array $data): array $components[] = [ 'component_type' => 'form_field', 'form_field_id' => $field->form_field_id, - 'custom_label' => $field->custom_label ?? $formField->label, + 'custom_label' => $field->custom_label ?? null, 'customize_label' => $field->customize_label ?? null, 'custom_data_binding_path' => $field->custom_data_binding_path ?? $formField->data_binding_path, 'customize_data_binding_path' => $field->custom_data_binding_path ?? null, @@ -246,7 +246,7 @@ protected function mutateFormDataBeforeFill(array $data): array $formFieldsData[] = [ 'form_field_id' => $field->form_field_id, 'label' => $field->label, - 'custom_label' => $field->custom_label ?? $formField->label, + 'custom_label' => $field->custom_label ?? null, 'customize_label' => $field->customize_label ?? null, 'custom_data_binding_path' => $field->custom_data_binding_path ?? $formField->data_binding_path, 'customize_data_binding_path' => $field->custom_data_binding_path ?? null,