-
Notifications
You must be signed in to change notification settings - Fork 576
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
[3.x] Set position on multi selects #2204
Conversation
@@ -168,7 +168,16 @@ | |||
if (this.taggable) { | |||
this.value = value | |||
} else { | |||
this.value = this.options.filter(o => value.includes(o.value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this chunk of js to ensure that the options are set to the order of how the id's come in. I believe this also needs to be in 2.x as otherwise it will take the order of all the available options (which is not sorted)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antonioribeiro can you share more about your use case for storing the position on multiselect? How are you using the field: which options do you use and how are the values loaded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @antonioribeiro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ifox, use case is basically when we need to read the selected items in the order we are selecting them.
On the screenshot below I selected "Education" first, because I want Education to be shown as the main sector in my blog post page.
When I save and reload the model, Education is no more the first item and the frontend will show "Housing" as the main sector:
It doesn't really matter how I'm getting these records later because their positions are all null
on the relationship table:
There will be no way for me to read them in the right order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how I'm creating the form field to test on Twill 3, where I get the same behaviour:
$form->add(
MultiSelect::make()
->name("sectors")
->inline()
->options(
Options::make(
Sector::all()
->map(
fn($sector) => Option::make(
$sector->id,
$sector->title
)
)
->toArray()
)
)
);
Port of #2167