Class: Ferro::Combo::Search

Inherits:
Form::Base show all
Defined in:
opal/opal-ferro/elements/ferro_combos.js.rb

Overview

Creates a form with a text input and a submit button. Specify option :button_text to set the submit button text. Specify option :placeholder to set a placeholder text for the input. Two states are defined: search-input-open, search-submit-open to define CSS rules.

Constant Summary

Constants included from Elementary

Elementary::RESERVED_NAMES

Instance Attribute Summary

Attributes inherited from BaseElement

#children, #domtype, #element, #parent, #sym

Instance Method Summary collapse

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, #after_create, #before_create, #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_createObject

Internal method.



13
14
15
16
# File 'opal/opal-ferro/elements/ferro_combos.js.rb', line 13

def _before_create
  @button_text = option_replace :button_text, ' '
  @placeholder = option_replace :placeholder, ' Search...'
end

#cascadeObject

Internal method.



19
20
21
22
# File 'opal/opal-ferro/elements/ferro_combos.js.rb', line 19

def cascade
  add_child :entry,  SearchInput,  { placeholder: @placeholder }
  add_child :submit, SearchSubmit, { content: @button_text }
end

#do_submitObject

Internal method.



25
26
27
28
29
30
31
32
33
34
# File 'opal/opal-ferro/elements/ferro_combos.js.rb', line 25

def do_submit
  value = entry.value.strip
  (value) if !value.empty?

  entry.toggle_state :search_input_open
  submit.toggle_state :search_submit_open

  entry.value = nil
  entry.set_focus if entry.state_active?(:search_input_open)
end

#submitted(value) ⇒ Object

Override this method to specify what happens when submit button is clicked or enter key is pressed.

Parameters:

  • value (String)

    The value of the text input.



40
# File 'opal/opal-ferro/elements/ferro_combos.js.rb', line 40

def (value);end