Class: Ferro::Form::Select
- Inherits:
-
BaseElement
- Object
- BaseElement
- Ferro::Form::Select
- Defined in:
- opal/opal-ferro/elements/ferro_form.js.rb
Overview
Creates a select list with options. In the DOM creates a: <select> and <option>. Specify option :list = Hash to set selectable options.
Constant Summary
Constants included from Elementary
Instance Attribute Summary
Attributes inherited from BaseElement
#children, #domtype, #element, #parent, #sym
Instance Method Summary collapse
-
#_before_create ⇒ Object
Internal method.
-
#add_option(value, content) ⇒ ElementVar
Manually add an option to the select element.
-
#after_create ⇒ Object
Internal method.
-
#changed ⇒ Object
Override this method to specify what happens after the select elements value is changed.
-
#select(option) ⇒ Object
Set the selected option.
-
#selection ⇒ Hash
Returns the currently selected option.
Methods inherited from BaseElement
#add_state, #add_states, #classify_state, #component, #dom_id, #factory, #get_text, #html, #initialize, #option_replace, #remove_attribute, #root, #router, #set_attribute, #set_text, #state_active?, #toggle_state, #update_state, #value, #value=
Methods included from Elementary
#_after_create, #_stylize, #add_child, #before_create, #cascade, #create, #creation, #destroy, #each_child, #forget_children, #method_missing, #remove_child, #style, #symbolize
Constructor Details
This class inherits a constructor from Ferro::BaseElement
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ferro::Elementary
Instance Method Details
#_before_create ⇒ Object
Internal method.
199 200 201 202 203 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 199 def _before_create @domtype = :select @list = option_replace :list, {} super end |
#add_option(value, content) ⇒ ElementVar
Manually add an option to the select element
225 226 227 228 229 230 231 232 233 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 225 def add_option(value, content) add_child( "opt_#{value}", Element::Var, domtype: :option, value: value, content: content ) end |
#after_create ⇒ Object
Internal method. TODO Use _after_create
207 208 209 210 211 212 213 214 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 207 def after_create @list.each do |value, content| add_option(value, content) end `#{@element}.addEventListener("change",function(e){#{changed};document.activeElement.blur()})` super end |
#changed ⇒ Object
Override this method to specify what happens after the select elements value is changed.
218 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 218 def changed;end |
#select(option) ⇒ Object
Set the selected option.
247 248 249 250 251 252 253 254 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 247 def select(option) `for(var i=0; i < #{element}.options.length; i++) { if (#{element}.options[i].value === #{option}) { #{element}.selectedIndex = i; break; } }` end |
#selection ⇒ Hash
Returns the currently selected option.
238 239 240 241 242 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 238 def selection option = `#{element}.options[#{element}.selectedIndex].value` text = `#{element}.options[#{element}.selectedIndex].text` { option: option, text: text } end |