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

feature: Implement multiple option for select field #3572

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

zhephyn
Copy link

@zhephyn zhephyn commented Jan 3, 2025

Description

Add a multiple boolean option to the select field, allowing for multiple selections.

Fixes #3426

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Manual review steps

Added two extra tests(one for selecting multiple sizes when creating a new product, another for editing the sizes list of an existing product) to the select_field_spec.rb file. These all pass when i run the command "bin/test ./spec/feature/avo/select_field_spec.rb".

Copy link

codeclimate bot commented Jan 3, 2025

Code Climate has analyzed commit 4931ab8 and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zhephyn

Thanks for this contribution. It's going on the right direction!

I left some comments on the code.

I also noticed that when multiple is true the show and index views are not showing the value as expected.

Let's address the code comments and the displaying issue before the next review.

Let me know if I can help.

Thank you!

lib/avo/fields/select_field.rb Outdated Show resolved Hide resolved
Comment on lines +3 to +8
include_blank: @field.include_blank,
multiple: @field.multiple,
aria: {
placeholder: @field.placeholder
},
include_hidden: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to put the aria inside the same hash as include_blank? Why aren't we keeping the same syntax as before?

I think include_hidden: false is causing an issue:

  1. Create a product with 2 random sizes
  2. Verify that sizes are correctly assigned
  3. Edit that product
  4. Deselect all the sizes
  5. Save
  6. Notice that product is keeping the 2 sizes instead empty

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of include_hidden: false was because, without it, when I select the sizes when creating a new product, an empty string is added as part of the submitted array. For example, if I was to select "large" and "small" as the sizes for a new product, on saving the product to the database, the array looks like this ["/","large","small"] without include_hidden: false. Should I remove it altogether or should I solve the error so that it can be kept? All in all, it's purpose was preventing the empty string from being saved as part of the sizes array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should remove or keep it, but this is the expected behavior:

If large and small is selected than the array should look like: ["large", "small"]

After having it saved as ["large", "small"] and on edit both are deselected the array should look like: []

Comment on lines +3 to +8
include_blank: @field.include_blank,
multiple: @field.multiple,
aria: {
placeholder: @field.placeholder
},
include_hidden: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
include_blank: @field.include_blank,
multiple: @field.multiple,
aria: {
placeholder: @field.placeholder
},
include_hidden: false
include_blank: @field.include_blank,
multiple: @field.multiple
},
aria: {
placeholder: @field.placeholder

spec/features/avo/select_field_spec.rb Outdated Show resolved Hide resolved
spec/features/avo/select_field_spec.rb Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement multiple option for select field.
2 participants