-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for selectable strings on edit pages
Feature: As an admin I want to select values from a drop-down rather than enter them free-form So that I don't need to worry about data integrity And so that I have a streamlined experience. Implementation: Add `Administrate::Field::Select` as an option to present string attributes. The field displays its attribute as a drop-down field on form pages. Usage in a dashboard: ```ruby kind: Field::Select.with_options(collection: Customer::KINDS), ```
- Loading branch information
1 parent
e9a7134
commit 3bccdb3
Showing
12 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<%# | ||
# Select Index Partial | ||
This partial renders a selectable text attribute, | ||
to be displayed on a resource's edit form page. | ||
## Local variables: | ||
- `f`: | ||
A Rails form generator, used to help create the appropriate input fields. | ||
- `field`: | ||
An instance of [Administrate::Field::Select][1]. | ||
A wrapper around the attribute pulled from the database. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Select | ||
%> | ||
|
||
<div class="field-unit__label"> | ||
<%= f.label field.attribute %> | ||
</div> | ||
<div class="field-unit__field"> | ||
<%= f.select( | ||
field.attribute, | ||
options_from_collection_for_select( | ||
field.selectable_options, | ||
:to_s, | ||
:to_s, | ||
field.data.presence, | ||
) | ||
) %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%# | ||
# Select Index Partial | ||
This partial renders a selectable text attribute, | ||
to be displayed on a resource's index page. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Select][1]. | ||
A wrapper around the attribute pulled from the database. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Select | ||
%> | ||
|
||
<%= field.data %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%# | ||
# Select Show Partial | ||
This partial renders a selectable text attribute, | ||
to be displayed on a resource's show page. | ||
## Local variables: | ||
- `field`: | ||
An instance of [Administrate::Field::Select][1]. | ||
A wrapper around the attribute pulled from the database. | ||
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Select | ||
%> | ||
|
||
<%= field.data %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require_relative "base" | ||
|
||
module Administrate | ||
module Field | ||
class Select < Field::Base | ||
def self.searchable? | ||
true | ||
end | ||
|
||
def selectable_options | ||
collection | ||
end | ||
|
||
private | ||
|
||
def collection | ||
@collection ||= options.fetch(:collection, []) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
spec/example_app/db/migrate/20160119024340_add_kind_to_customer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddKindToCustomer < ActiveRecord::Migration | ||
def change | ||
add_column :customers, :kind, :string, null: false, default: "standard" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters