Class: AgileFormFields::TextWithSelect
- Inherits:
-
Select
- Object
- AgileFormField
- Select
- AgileFormFields::TextWithSelect
- Defined in:
- app/models/agile_form_fields/text_with_select.rb
Overview
Implementation of text_with_select AgileRails form field. Field will provide text_field entry field with select dropdown box with optional values for the field. Form options are mostly same as in select field.
Form options:
-
name:field name (required) -
type:text_with_select (required) -
choices:Values for choices separated by comma. Values can also be specified like description:value.
In this case description will be shown to user, but value will be saved to document.
choices: 'OK:0,Ready:1,Error:2'
choices: Ruby,Pyton,PHP
-
choices: eval Choices will be provided by evaluating expression choices: eval agile_choices_for(‘model_name’,‘description_field_name’,‘_id’); agile_choices_for helper will provide data for select field. choices: eval ModelName.choices_for_field; ModelName class will define method choices_for_field which will provide data for select field. Since expression is evaluated in the context of Form Field object
Even session session variables can be accessed.
choices: eval MyClass.method(@env.session[:user_id])
When searching is more complex custom search method may be defined in CollectionName model which will provide dataset for search.
choices: eval collection_name.search_field_name.method_name;
If choices or eval is not defined choices will be provided from translation helpers. For example: Collection has field status. Choices for field will be provided by en.helpers.model_name.choices_for_status entry of english translation. English is of course default translation. If you provide translations in your local language then select choices will be localized.
en.helpers.model_name.choices_for_status: 'OK:0,Ready:1,Error:2'
sl.helpers.model_name.choices_for_status: 'V redu:0,Pripravljen:1,Napaka:2'
-
html:html options which apply to select and text_field fields (optional)
Form example:
10:
name: link
type: text_with_select
choices: eval @env.agile_page_class.all_pages_for_site(@env.agile_get_site)
size: 50
Instance Attribute Summary
Attributes inherited from AgileFormField
Instance Method Summary collapse
-
#render ⇒ Object
Render text_with_select AgileRails form field code.
Methods inherited from Select
#add_view_code, #choices_in_eval, #choices_in_locales, #get_choices, get_data, #ro_standard
Methods inherited from AgileFormField
get_data, #hash_to_options, #html, #initialize, #options_to_hash, #record_text_for, #ro_standard, #set_css_code, #set_default_value, #set_initial_value, #set_style, #t
Constructor Details
This class inherits a constructor from AgileFormFields::AgileFormField
Instance Method Details
#render ⇒ Object
Render text_with_select AgileRails form field code
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/agile_form_fields/text_with_select.rb', line 66 def render set_initial_value('html','value') record = record_text_for(@yaml['name']) @html += @env.text_field( record, @yaml['name'], @yaml['html']) @yaml['html']['class'] ||= '' @yaml['html']['class'] += ' text-with-select' @yaml['html'].symbolize_keys! unless @readonly @html += @env.select( @yaml['name'] + '_', nil, get_choices, { include_blank: true }, { class: 'text-with-select' }) end # javascript to update text field if new value is selected in select field @js =<<EOJS $(document).ready(function() { $('##{@yaml['name']}_').change( function() { if ($(this).val().toString().length > 0) { $('##{record}_#{@yaml['name']}').val( $(this).val() ); $('##{record}_#{@yaml['name']}').trigger("change"); } $('##{record}_#{@yaml['name']}').focus(); }); }); EOJS self end |