Class: Forma::SelectField
- Inherits:
-
SimpleField
- Object
- Field
- SimpleField
- Forma::SelectField
- Defined in:
- lib/forma/field.rb
Overview
Selection field.
Instance Attribute Summary
Attributes inherited from Field
#actions, #after, #autofocus, #before, #child_model_name, #height, #hint, #i18n, #icon, #inline_hint, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #turbolink, #url, #value, #width
Instance Method Summary collapse
- #edit_element(val) ⇒ Object
- #id_field_name ⇒ Object
-
#initialize(h = {}) ⇒ SelectField
constructor
A new instance of SelectField.
- #type_field_name ⇒ Object
- #view_element(val) ⇒ Object
Methods inherited from SimpleField
Methods inherited from Field
#action, #id, #localization_key, #localized_hint, #localized_label, #name_as_chain, #parameter_name, #to_html
Methods included from Html
Methods included from Utils
extract_value, number_format, #simple_value, singular_name
Constructor Details
#initialize(h = {}) ⇒ SelectField
Returns a new instance of SelectField.
531 532 533 534 535 536 537 538 |
# File 'lib/forma/field.rb', line 531 def initialize(h={}) h = h.symbolize_keys @search_url = h[:search_url] @search_width = h[:search_width] || 500 @search_height = h[:search_height] || 600 @polymorphic = h[:polymorphic] super(h) end |
Instance Method Details
#edit_element(val) ⇒ Object
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/forma/field.rb', line 554 def edit_element(val) inputs = [ el('input', attrs: { id: "#{self.id}_id_value", type: 'hidden', value: "#{val and val.id}", name: id_field_name }) ] if @polymorphic inputs << el('input', attrs: { id: "#{self.id}_type_value", type: 'hidden', value: "#{val and val.class.to_s}", name: type_field_name } ) end text_element = el( 'span', attrs: { id: "#{self.id}_text", class: ['ff-select-label', ('ff-empty' if val.blank?)] }, text: (val.present? ? val.to_s : Forma.config.texts.empty) ) = el('div', attrs: { class: 'btn-group' }, children: [ el('a', attrs: { class: 'ff-select-link btn btn-mini btn-default btn-xs', 'data-id' => self.id, 'data-url' => @search_url, 'data-width' => @search_width, 'data-height' => @search_height }, children: [ el('i', attrs: { class: 'icon icon-search fa fa-search' }) ]), el('a', attrs: { class: 'ff-clear-selection-action btn btn-mini btn-default btn-xs', 'data-id' => self.id }, children: [ el('i', attrs: { class: 'icon icon-trash fa fa-trash-o' }) ]) ]) children = inputs + [ text_element, ] el('div', attrs: { id: self.id, class: 'ff-select-field' }, children: children) end |
#id_field_name ⇒ Object
540 541 542 543 544 |
# File 'lib/forma/field.rb', line 540 def id_field_name chain = name_as_chain chain[chain.length - 1] = "#{chain.last}_id" parameter_name_from_chain(chain) end |
#type_field_name ⇒ Object
546 547 548 549 550 |
# File 'lib/forma/field.rb', line 546 def type_field_name chain = name_as_chain chain[chain.length - 1] = "#{chain.last}_type" parameter_name_from_chain(chain) end |
#view_element(val) ⇒ Object
552 |
# File 'lib/forma/field.rb', line 552 def view_element(val); el(@tag || 'span', text: val.to_s) end |