laravel / nova-issues

557 stars 34 forks source link

Multiselect readonly with dependsOn: doesn't work #4946

Closed phlisg closed 2 years ago

phlisg commented 2 years ago

Description:

Trying to influence the readonly attribute of a MultiSelect field with a dependsOn doesn't work.

When adding a dependsOn rule to manipulate the readonly attribute, it seems like it is evaluated on page load and then nothing happens. I do see the requests being sent via XHR to toggle the field, but nothing happens.

Everything works fine with show() and hide(). I'm using the same thing for Select fields with no issues.

Detailed steps to reproduce the issue on a fresh Nova installation:

  1. Create a basic resource
  2. Add this in the resource's fields():
// the column doesn't exist, the "sync_myfield" is intercepted during `Model::saving()` and removed.
Boolean::make('Edit anyway', 'sync_myfield'), 

MultiSelect::make('Unlockable field', 'column')
  ->options(['option1' => 'Option 1', 'option2' => 'Option 2'])
  ->dependsOn(['sync_myfield'], fn($field, $request, $data) => $field->readonly( ! $data->sync_myfield))
  ->readonly(),

// This works
MultiSelect::make('Unlockable field', 'column')
  ->options(['option1' => 'Option 1', 'option2' => 'Option 2'])
  ->dependsOn(['sync_myfield'], fn($field, $request, $data) => $data->sync_myfield ? $field->show() : $field->hide())
  1. Edit an existing resource, click on the "edit anyway" checkbox: the field doesn't toggle readonly.
github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.