Class: Ferro::Form::Input
- Inherits:
-
BaseElement
- Object
- BaseElement
- Ferro::Form::Input
- Defined in:
- opal/opal-ferro/elements/ferro_form.js.rb
Overview
Creates an input element. In the DOM creates a: <input type=“?”>. Specify option :type to set the location. Use one of these values: :text, :password, :reset, :radio, :checkbox, :color, :date, :datetime-local, :email, :month, :number, :range, :search, :tel, :time, :url, :week. Or leave blank to create a :text input.
Direct Known Subclasses
Constant Summary
Constants included from Elementary
Instance Attribute Summary
Attributes inherited from BaseElement
#children, #domtype, #element, #parent, #sym
Instance Method Summary collapse
-
#_after_create ⇒ Object
Internal method.
-
#_before_create ⇒ Object
Internal method.
-
#disable ⇒ Object
Disable this input.
-
#enable ⇒ Object
Enable this input.
-
#entered ⇒ Object
Callback for :text, :password, :number types.
-
#keydowned(event) ⇒ Object
Callback for :text, :password, :number types.
-
#set_focus ⇒ Object
Set input focus to this element.
-
#value ⇒ Object
Getter method for input value.
-
#value=(value) ⇒ Object
Setter method for input value.
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
Methods included from Elementary
#_stylize, #add_child, #after_create, #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
#_after_create ⇒ Object
Internal method.
52 53 54 55 56 57 58 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 52 def _after_create disable if @disabled if [:text, :password, :number].include?(@options[:type]) `#{@element}.addEventListener("keydown",function(e){self.$keydowned(e);})` end end |
#_before_create ⇒ Object
Internal method.
28 29 30 31 32 33 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 28 def _before_create @domtype = :input @options[:type] ||= :text @options[:value] = option_replace :content @disabled = option_replace :disabled, false end |
#disable ⇒ Object
Disable this input.
71 72 73 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 71 def disable set_attribute(:disabled, :disabled) end |
#enable ⇒ Object
Enable this input.
76 77 78 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 76 def enable remove_attribute(:disabled) end |
#entered ⇒ Object
Callback for :text, :password, :number types. Override this method to catch the ‘enter’ key.
68 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 68 def entered;end |
#keydowned(event) ⇒ Object
Callback for :text, :password, :number types. Catches ‘enter’ key and calls ‘entered`.
62 63 64 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 62 def keydowned(event) entered if Native(event).keyCode == 13 end |
#set_focus ⇒ Object
Set input focus to this element. TODO: Find out why this doesn’t seem to work.
47 48 49 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 47 def set_focus `#{element}.focus()` end |
#value ⇒ Object
Getter method for input value.
36 37 38 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 36 def value `#{@element}.value` end |
#value=(value) ⇒ Object
Setter method for input value.
41 42 43 |
# File 'opal/opal-ferro/elements/ferro_form.js.rb', line 41 def value=(value) `#{@element}.value = #{value}` end |