README.md in activeadmin_selectize-0.1.4 vs README.md in activeadmin_selectize-0.1.5

- old
+ new

@@ -23,24 +23,12 @@ ``` - Use the input with `as: :selectize` in Active Admin model conf Why 2 separated scripts? In this way you can include a different version of Selectize.js if you like. -## Notes +## Examples -- In ActiveAdmin json routes should be enabled by default, this behavior is controlled by *download_links* option for index action. Example: - -```rb -index download_links: [:csv, :json] do - # ... -end -``` - -- If the select items "gets cut" by the container try adding: `'data-opts': '{"dropdownParent":"body"}'` - -## Example - Example 1: an Article model with a many-to-many relation with Tag model: ```ruby class Article < ApplicationRecord has_and_belongs_to_many :tags @@ -68,10 +56,32 @@ filter :name_eq, as: :selectize, collection: Author.all.pluck( :name, :name ) # With remote items: filter :tags_id_eq, as: :selectize, collection: [], input_html: { 'data-opt-remote': '/admin/tags.json', 'data-opt-text': 'name', 'data-opt-value': 'id', 'data-opts': '{"dropdownParent":"body"}', placeholder: 'Search a tag...' } ``` +## Notes + +- In ActiveAdmin json routes should be enabled by default, this behavior is controlled by *download_links* option for index action. Example: + +```rb +index download_links: [:csv, :json] do + # ... +end +``` + +You can customize the JSON response overriding the *as_json* method of the model: + +```rb +def as_json( options = nil ) + super({ only: [:id], methods: [:fullname] }.merge(options || {})) +end +``` + +- If the select items "gets cut" by the container try adding: `'data-opts': '{"dropdownParent":"body"}'` + +- Alternative syntax to pass data attributes: `input_html: { data: { opts: '{}' } }` + ## Options Pass the required options using `input_html`. - **data-opt-remote**: URL used for AJAX search requests (method GET) @@ -80,9 +90,15 @@ - **data-opt-NAME**: option _NAME_ passed directly to Selectize.js - see [options](https://github.com/selectize/selectize.js/blob/master/docs/usage.md#configuration) Alternative syntax: - **data-opts**: overrides Selectize options - example: `'data-opts': '{"highlight":true,"plugins":[]}'` + +## Do you like it? Star it! + +If you use this component just star it. A developer is more motivated to improve a project when there is some interest. + +Take a look at [other ActiveAdmin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source) that I made if you are curious. ## Contributors - [Mattia Roccoberton](http://blocknot.es) - creator, maintainer