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 9 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],
   )

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.

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.

Add max_items, selected, multiple and include_blank.

Added functionality to select, updated simuluscontroller to listen to the added data attributes, Updated Trix editor
@nickcharlton
Copy link
Member

I rebased this to see if I could move it along, but it needs a bit more work.

  1. The tests are failing with:
fields/select/_form uses the selected value when given
     Failure/Error: multiple: field.options[:multiple],
       #<InstanceDouble(Administrate::Field::Select) (anonymous)> received unexpected message :options with (no args)
  1. We should add a feature tests so that we're testing the JavaScript behaviour,
  2. We need to document the changes so other people know about it

@nickcharlton nickcharlton added views-and-styles how administrate looks and is interacted with fields new fields, displaying and editing data javascript Pull requests that update Javascript code labels Jan 20, 2025
@Thrizian
Copy link
Author

Thanks for the rebase. I'll look into it when i find the time. Kinda working on my side project (Kamal 2, Rails 8) it does include administrate so i'll look into what i think needs love to reach the new rails standards :D.

I do expect time to be limited as i'm awaiting the birth of my firstborn, which is bound to happen 1 or 2 months.

@nickcharlton
Copy link
Member

No worries! And of course, completed expected.

I was hoping to get the last bit over the line for you, but I'll leave you to it!

most people won't use this.
Added functionality to select, updated simuluscontroller to listen to the added data attributes, Updated Trix editor
…ild:css

Added functionality to select, updated simuluscontroller to listen to the added data attributes, Updated Trix editor
@Thrizian
Copy link
Author

So i guess some of this does not work < 7. afaik this does not introduce breaking changes though.

Am i right to state that:

  1. i should build an example in the spec/example_app.
  2. write some documentation.

Anything else?

@nickcharlton
Copy link
Member

I think that's it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fields new fields, displaying and editing data javascript Pull requests that update Javascript code views-and-styles how administrate looks and is interacted with
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants