filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.98k stars 2.93k forks source link

Inconsistent "data" passed to DataAware Rules #9107

Closed DSpeichert closed 1 year ago

DSpeichert commented 1 year ago

Package

filament/filament

Package Version

v3.0.76

Laravel Version

v10.28.0

Livewire Version

v3.0.8

PHP Version

PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS)

Problem description

Expected behavior

All form fields should be available as provided to validator as when called like this:

Validator::make([
    'type' => 'A',
    'data' => '1.2.3.4',
], [
        'data' => [
            'required',
            new App\Rules\DnsRecord(), // this rule can access `type` value
        ],
    ]
)->validate();

Steps to reproduce

  1. Create a DataAware Rule
  2. Create relationship manager and use the DataAware Rule in the form
  3. Data-Aware Rule is not receiving the data

Reproduction repository

https://github.com/DSpeichert/repro-data-aware-rule

Relevant log output

Custom Page using Form receives `data` nested under `data` key:

array:13 [▼ // app/Rules/DnsRecord.php:36
  "data" => array:3 [▼
    "name" => "test"
    "type" => "A"
    "data" => "1.2.3.4.5"
  ]
  "mountedActions" => []
  "mountedActionsArguments" => []
  "mountedActionsData" => []
  "componentFileAttachments" => []
  "mountedFormComponentActions" => []
  "mountedFormComponentActionsArguments" => []
  "mountedFormComponentActionsData" => []
  "mountedFormComponentActionsComponents" => []
  "mountedInfolistActions" => []
  "mountedInfolistActionsData" => []
  "mountedInfolistActionsComponent" => null
  "mountedInfolistActionsInfolist" => null
]

In relationship manager's form the data key is missing in the data passed to DataAware Rule:

array:33 [▼ // app/Rules/DnsRecord.php:36
  "ownerRecord" => array:63 [▶]
  "pageClass" => "App\Filament\Resources\DomainResource\Pages\ViewDomain"
  "mountedActions" => []
  "mountedActionsArguments" => []
  "mountedActionsData" => []
  "componentFileAttachments" => []
  "mountedFormComponentActions" => []
  "mountedFormComponentActionsArguments" => []
  "mountedFormComponentActionsData" => []
  "mountedFormComponentActionsComponents" => []
  "mountedInfolistActions" => []
  "mountedInfolistActionsData" => []
  "mountedInfolistActionsComponent" => null
  "mountedInfolistActionsInfolist" => null
  "activeTab" => null
  "isTableLoaded" => false
  "tableGrouping" => null
  "tableGroupingDirection" => null
  "tableRecordsPerPage" => 10
  "isTableReordering" => false
  "tableColumnSearches" => []
  "tableSearch" => ""
  "tableSortColumn" => null
  "tableSortDirection" => null
  "toggledTableColumns" => []
  "mountedTableActions" => array:1 [▶]
  "mountedTableActionsData" => array:1 [▶]
  "mountedTableActionRecord" => null
  "selectedTableRecords" => []
  "mountedTableBulkAction" => null
  "mountedTableBulkActionData" => []
  "tableFilters" => array:1 [▶]
  "paginators" => array:1 [▶]
]
danharrin commented 1 year ago

Currently, we do not support DataAwareRule in forms - because we have $get() instead, which can be used to contextually fetch data from other fields in a much more intuitive way.

https://filamentphp.com/docs/3.x/forms/validation#custom-rules