Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug: Multiple BelongsToSelect fields. When trying to change value of one will reset the value of the other one #197

Merged
merged 2 commits into from
Mar 12, 2021

Conversation

s-sadiq
Copy link
Contributor

@s-sadiq s-sadiq commented Mar 12, 2021

Describe the bug
Having multiple BelongsToSelect fields with the default options without using ->preload() produce a strange behavior. Trying to change one field will reset the value of the other field.

To reproduce
Steps to reproduce the behavior:

  1. Create a resource with 3 BelongsToSelect fields without ->preload() option
  2. Search in the first select field and select a value from the list
  3. Search in the second select field and select a value from the list
  4. Search in the third select field will cause the first field to reset value.

The issue can also be reproduced using 2 select fields with ->dependable() option. Which will remove .defer option.

Expected behavior
Search in one of the select fields should not reset the value of the other fields.

Code

    public static function form(Form $form)
    {
        return $form
            ->schema([
                BelongsToSelect::make('work_type_id')->relationship('workType', 'name')->required(),
                BelongsToSelect::make('work_priority_id')->relationship('workPriority', 'name')->required(),
                BelongsToSelect::make('asset_id')->relationship('asset', 'name')->required()
            ]);
    }

Screenshots
issue

Context

  • Package version: v1.5.5
  • Livewire version: v2.4.0
  • Laravel version: v8.32.1
  • Browser: Chrome & firefox
  • Server OS: macOS Big Sur 11.2.3 (Laravel Valet 2.13.19)
  • PHP version: 8.0.2
  • Database: MySQL 8.0

Proposed fix
change on value watcher

this.$watch('value', () => {
	if (this.value in this.options) {
		this.displayValue = this.options[this.value]
	}
})

@danharrin danharrin changed the base branch from main to develop March 12, 2021 16:38
@danharrin danharrin added the bug Something isn't working label Mar 12, 2021
@danharrin danharrin merged commit 77975e0 into filamentphp:develop Mar 12, 2021
@danharrin
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants