[R] | select_field | |
[R] | select_options | |
[R] | value_field |
Provides the Model content in a ready to use <select>
options array
Params
-
:options
-
:prompt [String/Boolean] => The text shown on the
<select>
field in the browser. (Defaults to “Select NameOfYourModel”) -
:divider [Boolean] => Whether to add a divider/separator between the prompt and the main options. (Defaults to
true
) -
:order [Array] => A normal DM order declaration. (Defaults to [:name] or the name of the #select_field declared)
-
:show_root [Boolean] => Whether to add the Top Level Parent in the choices. (Defaults to
true
) -
:root_text [String] => The text to show as the Parent item in select list. (Defaults to “Top Level NameOfYourModel”)
-
Examples
Category.items_for_select_menu => [ [nil, 'Select Category'], [nil, '---'], [1, 'Category 1'] ,....] Category.items_for_select_menu(:prompt => "Custom Prompt") => [ [nil, 'Custom Prompt'],...] Category.items_for_select_menu(:prompt => false) => [ [1, 'Category 1'] ,...] Category.items_for_select_menu(:divider => false ) => array without the [nil, '---'] node Category.items_for_select_menu(:order => [ :id.desc ] ) => array with the order reversed. (Prompts & divider always comes first) Category.items_for_select_menu(:publish_status => "on", :order => [ :id.desc ] ) => returns only those items that matches the query params or just an empty Select Menu
If your model is a Tree:
Category.items_for_select_menu(:root_text => "Custom Root Text") # sets the text for the Top Level (root) Parent => [ ..., [0, 'Custom Root Text'],...] Category.items_for_select_menu(:show_root => false) # removes the Top Level (root) Parent from the
@api public
Source: show