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

Add options for select field. #2683

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

Conversation

Thrizian
Copy link

@Thrizian Thrizian commented Oct 11, 2024

This PR is a followup of: #2676

I've had another go at this. Since i figured out how to get the application up and running locally, #rtfm. I'm pretty bad at writing tests so perhaps someone can help me with writing some better coverage. Is it sufficient to write a test that validates whether a data attribute is slapped onto the select input? Or do i also need to write tests that validate the working of my PR clientside(the stimulus controller) I have no experience testing stimuluscontrollers.

This should get us a nice start to get some more selectize functionality.

I've used the SelectController Stimulus Controller to handle this. We are using data attributes to get the message passed across.

This PR now adds:

  • selected
  • multiple
  • max_items
  • include_blank

Max items. Allows for selecting items up to max_items.

    kind: Field::Select.with_options(
      collection: [1,2,3,4],
      max_items: 2
    )

Multiple selecting multiple options.

    kind: Field::Select.with_options(
      collection: [1,2,3,4],
      selected: 4,
      max_items: 2
    )

Selected, allows for the selection of a specific element or multiple elements.

    kind: Field::Select.with_options(
      collection: [1,2,3,4],
      selected: 4,
    )
   kind: Field::Select.with_options(
     collection: [1,2,3,4],
     selected: [2,4],
   )

This also works with [[1, 2],[3,4],[5,6]]

   kind: Field::Select.with_options(
     collection: [[1, 2],[3,4],[5,6]],
     selected: [2,4],
   )

Introduced a 'selected' option in the Select field to specify a default value when no data is available. Updated the form partial to prioritize 'selected' over data and added related test cases to ensure correct behavior. Updated .gitignore and added .tool-versions for environment settings.
most people won't use this.
Added functionality to select, updated simuluscontroller to listen to the added data attributes, Updated Trix editor
Copy link
Author

@Thrizian Thrizian left a comment

Choose a reason for hiding this comment

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

I've read through this

@Thrizian
Copy link
Author

There are some merge conflicts on the application.js and application.js.map files. I'm a bit new to builds/ folders should i have or not have added those?

@nickcharlton
Copy link
Member

We're going to try updating the builds in each commit/original PR to make things a bit easier, so they'll likely clash now.

You can do something like:

git checkout HEAD -- app/assets/builds/administrate/application.js
git checkout HEAD -- app/assets/builds/administrate/application.js.map
yarn build; yarn build:css

to get new versions and not worry about the conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants